你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Overview
Azure Resource Manager enables you to work with the resources in your solution as a group. For more information about Resource Manager, see Azure Resource Manager overview.
Management library
The Azure Resource Manager library for .NET enables you to create, update, delete, and list resources and resource groups.
Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.
Visual Studio Package Manager
Install-Package Azure.ResourceManager
dotnet add package Azure.ResourceManager
Example
This example creates a new resource group.
// First, initialize the ArmClient and get the default subscription
ArmClient client = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroupResource collection for that subscription
SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();
ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();
// With the collection, we can create a new resource group with an specific name
string resourceGroupName = "myRgName";
AzureLocation ___location = AzureLocation.WestUS2;
ResourceGroupData resourceGroupData = new ResourceGroupData(___location);
ArmOperation<ResourceGroupResource> operation = await resourceGroups.CreateOrUpdateAsync(WaitUntil.Completed, resourceGroupName, resourceGroupData);
ResourceGroupResource resourceGroup = operation.Value;