A handy .NET global tool to deploy resources to Azure

If you haven't used the Azure CLI yet, download it now, it is great for deploying Azure resources from the command line. For example, to create a resource group named awesomesauce in the West Europe data-center location, simply just execute:

az group create --location westeurope --rg-name awesomesauce  

It was also suggested to deploy resources using the Azure CLI instead of using Azure ARM scripts, which can become quite a nightmare if you are a ARMateur like me. See what I did there?

The only downside is that there are no batch-execution support (yet), so in the meanwhile we are left to execute only one statement at a time.

Introducing dotnet az

Disclaimer: The following tool/product is not tested (yet) for production scenarios nor has it been endorsed by Microsoft, as it is considered experimental at this stage.

Given the limitation of single executions, it got me thinking to create a simple .NET global tool to deploy resources from one or many script files containing many Azure CLI commands.

Source code is available on GitHub here.

Given a directory containing a script file called website.azcli with the following:

$resourceGroup = "AwesomeGroup"
$location = "westeurope"
$plan = "awesomeplan"

az group create --location $location --rg-name $resourceGroup  

az appservice plan create --name $plan --resource-group $resourceGroup --location $location

az webapp create --name fanieawesomesauce --resource-group $resourceGroup --plan $plan  

We can execute the following command:

dotnet az deploy website.azcli  

Or even specify a directory containing multiple *.azcli files:

dotnet az deploy .  
Note that although it all executes from one command, it still executes each Azure CLI command separately in the background.

Basically, all that the dotnet-az global tool is doing, is aggregating the contents of the specified *.azcli file(s) and wrapping them in a Powershell script, which gets executed in one go. This allows us to also utilize variables in the scripts.

Did you know? There is already an existing VSCode extension that natively understands *.azcli files with full Intellisense support for the Azure CLI.


As a prerequisite, you would need to have the Azure CLI and Azure Powershell installed, and obviously the .NET Core SDK. To install this global tool, run the following:

dotnet tool install --global dotnet-az  


To use it, like any other Azure CLI interface, you need to be logged in. For the current version, you can either need to call az login every time before executing az deploy, or you can use the tool's import functionality to import an existing Azure profile context (imported using Get-AzureRmContext):

dotnet az import-profile <path of existing azure context file>
Source code is available on GitHub here.