I am following the new Azure.ResourceManager SDK examples here.
I'm not seeing classes I'd expect to see in Azure.ResourceManager.Resources. Specifically, ArmDeploymentCollection and ResourceGroupResource doesn't have a GetArmDeployments() method.
Azure.ResourceManager installed is Azure.ResourceManager.1.0.0. I'm targeting .NET framework 4.8.
I've tried uninstalling/re-installing Azure.ResourceManager several times, but doesn't change anything.
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);
}
}
}
I resolved the issue by adding a reference to Azure.ResourceManager.Resources.dll. Not sure why this reference isn't added when the nuget package is installed.