c# - 获取订阅下的所有容器注册表 - .NET Azure sdk

标签 c# asp.net azure azure-sdk-.net azure-container-registry

查找 .NET SDK 引用以获取指定的容器注册表或资源组或订阅中的所有容器注册表。

除了可用的 REST API 之外还需要引用: https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/registries?api-version=2019-05-01

我发现可以通过 Powershell 和 CLI cmdlet 进行该操作; Get-AzContainerRegistryaz acr list,但请查找基于 .NET SDK 的库引用(首选 Azure.ResourceManager)。

我已经浏览过https://github.com/Azure/azure-sdk-for-net ,但没有与获取特定容器注册表或列出订阅下的容器注册表相关的扩展。

最佳答案

Nuget 包:

// Change these as needed
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();

// You can also get the resource group first if you know it already
// subscription.GetResourceGroups().Get("myresourcegroup");
var registyResources = subscription.GetGenericResourcesAsync("resourceType eq 'Microsoft.ContainerRegistry/registries'").AsPages();

await foreach (var resource in registyResources)
{
    var id = resource.Values.First().Id;
    Console.WriteLine($"Id: {id}");
    Console.WriteLine($"Resource Group: {id.ResourceGroupName}");
    Console.WriteLine($"Container registry name: {id.Name}");
}

如果您需要任何其他信息,还可以浏览返回的资源。然后您可以继续使用 specialized SDK对于特定的容器注册表。

关于c# - 获取订阅下的所有容器注册表 - .NET Azure sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71063410/

相关文章:

c# - 使用 sgen 垃圾收集器运行单一服务

c# - 制作一个 Twitter 单声道客户端

c# - 在上传期间调整和优化网页图像的最佳类别是什么?

c# - 在未安装 Office 的情况下在服务器上操作 Word 文档 (ASP.NET)

visual-studio - 通过 Visual Studio 将 ASP.NET Web API 发布到 Azure 时出错

Azure Blob 存储作为源,FTP 作为目标

.net - 从 Windows Azure 表下载数据的最佳方式

c# - 在 SQLite 中向表添加时间戳字段

c# - sqlite,如何避免在删除父记录时插入新记录?我使用 C# 和 EF 4.4

asp.net - 在ASP.NET中使用Web API而不是Web方法的优点是什么