skip to Main Content

How can I create an Azure Storage Account programmatically using c# or vb but without using the nuget package Microsft.Azure.Management.Storage as it is deprecated.
All the code I am finding is using this deprecated package.

2

Answers


  1. I use the Azure.Storage.Blobs package

    dotnet add package Azure.Storage.Blobs
    

    Updated documentation can be found at the link below

    https://learn.microsoft.com/en-us/dotnet/api/overview/azure/storage.blobs-readme?view=azure-dotnet

    Login or Signup to reply.
  2. As mentioned in the comments, the Nuget package you would want to use is Azure.ResourceManager.Storage.

    Here’s the sample code for creating a storage account taken from here.

    using System;
    using System.Threading.Tasks;
    using Azure.Identity;
    using Azure.ResourceManager.Storage.Models;
    using Azure.ResourceManager.Resources;
    using NUnit.Framework;
    using Azure.Core;
    
    ArmClient armClient = new ArmClient(new DefaultAzureCredential());
    SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
    
    string rgName = "myRgName";
    AzureLocation location = AzureLocation.WestUS2;
    ArmOperation<ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));
    ResourceGroupResource resourceGroup = operation.Value;
    
    //first we need to define the StorageAccountCreateParameters
    StorageSku sku = new StorageSku(StorageSkuName.StandardGrs);
    StorageKind kind = StorageKind.Storage;
    string location = "westus2";
    StorageAccountCreateOrUpdateContent parameters = new StorageAccountCreateOrUpdateContent(sku, kind, location);
    //now we can create a storage account with defined account name and parameters
    StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts();
    string accountName = "myAccount";
    ArmOperation<StorageAccountResource> accountCreateOperation = await accountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, parameters);
    StorageAccountResource storageAccount = accountCreateOperation.Value;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search