ArmDeploymentCollection 不在 Azure.ResourceManager.Resources 命名空间中

ArmDeploymentCollection Not in Azure.ResourceManager.Resources Namespace

我正在关注新 Azure.ResourceManager SDK examples here

我没有看到 类 我希望在 Azure.ResourceManager.Resources 中看到。具体来说,ArmDeploymentCollection 和 ResourceGroupResource 没有 GetArmDeployments() 方法。

Azure.ResourceManager 安装的是 Azure.ResourceManager.1.0.0。我的目标是 .NET Framework 4.8。

我试过 uninstalling/re-installing Azure.ResourceManager 几次,但没有任何改变。

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.IO;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.KeyVault;
using System.Threading;
using Azure;
using Azure.Identity;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;

    public static void Initialize()
    {
        try
        {
            // Authenticate
            var credentials = new DefaultAzureCredential();

            await RunSample(credentials);
        }
        catch (Exception ex)
        {
            Utilities.Log(ex);
        }

    }

    public static async Task RunSample(TokenCredential credential)
    {

        try
        {
            var deploymentName = "bradDeployment";
            var rgName = "rg-percipience-test-002";
            var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var templateJson = Utilities.GetArmTemplate("ArmTemplate.json");

            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
            ResourceGroupCollection rgCollection = subscription.GetResourceGroups();
            // With the collection, we can create a new resource group with an specific name
            AzureLocation location = AzureLocation.EastUS;
            ArmOperation<ResourceGroupResource> lro = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));
            ResourceGroupResource resourceGroup = lro.Value;
            
            Utilities.Log("Created a resource group with name: " + rgName);
            
            // Create a deployment for an Azure App Service via an ARM
            // template.
            
            Utilities.Log("Starting a deployment for an Azure App Service: " + deploymentName);

            // First we need to get the deployment collection from the resource group
            ArmDeploymentCollection armDeploymentCollection = resourceGroup.GetArmDeployments();
            // Use the same location as the resource group
            // Passing string to template and parameters
            var input = new ArmDeploymentContent(new ArmDeploymentProperties(ArmDeploymentMode.Incremental)
            {
                Template = BinaryData.FromString(File.ReadAllText("storage-template.json")),
                Parameters = BinaryData.FromString(File.ReadAllText("storage-parameters.json"))
            });
            ArmOperation<ArmDeploymentResource> lro2 = await ArmDeploymentCollection.CreateOrUpdateAsync(WaitUntil.Completed, deploymentName, input);
            ArmDeploymentResource deployment = lro2.Value;

            Utilities.Log("Completed the deployment: " + deploymentName);
        }
        finally
        {
            try
            {
                Utilities.Log("Deleting Resource Group: " + rgName);

                await (await resourceGroups.StartDeleteAsync(rgName)).WaitForCompletionAsync();

                Utilities.Log("Deleted Resource Group: " + rgName);
            }
            catch (Exception ex)
            {
                Utilities.Log(ex);
            }
        }

    }

我通过添加对 Azure.ResourceManager.Resources.dll 的引用解决了这个问题。不确定为什么在安装 nuget 包时没有添加此引用。