Change Default Azure Subscription for Visual Studio

1.6k views Asked by At

I work at a company that has plenty of Azure subscriptions. In Visual Studio, it appears that my 'DefaultAzureSubscription' will not change (or I just dont know how to do it).

For example, I use the below method to initialize my subscription that I want to work in:

    public async Task CreateCommonClient()
    {
       ArmClient = GetArmClient();
       Subscription = await ArmClient.GetDefaultSubscriptionAsync();
    }

It always defaults to subscription that I do not want to work in.

Does anyone know how to change VS default subscriptions? Please and thank you!

1

There are 1 answers

1
Jahnavi On

To change default subscriptions in Visual Studio, I could be able to achieve it using AzureCloudBash in Vs code terminal.

az account subscription enable --subscription-id "<subscriptionID>"

Or

 az account set --subscription "<subscriptionID>"

Note: The az account set command does not allow you to switch your active subscription to a subscription in a different tenant. To continue, you must first log in as a user within the desired tenant. You will get the following problem if you attempt to set your subscription to a subscription in a different tenant:

Refer MSDoc

When I tried in my environment before logging in, I got the same result:

enter image description here

A tenant must have complete control over all active subscriptions in order to change an active subscription. I would suggest you to use the following command and execute it by changing tenant.

az login --tenant "<TenantID>"

enter image description here

You can obtain the active tenant list by using the below command: (if needed)

enter image description here

Reference: az account

As an alternative, we can choose subscriptions using the command palette, as I suggested in a comment:

Path: "view -> commandPalette -> Azure: Select Subscriptions" (ctrl+shift+p) enter image description here