Deploy a .NET 6 Web Application to an Azure App Service by the command line

Emanuele Bartolesi - Aug 18 '22 - - Dev Community

CI/CD is a good approach to deploy web applications (and not only web applications) but there a lot of reasons for not configuring an entire workflow from the beginning of the project (disclaimer: I am a big fan of CI/CD or GitHub Actions or Azure DevOps).

We will use the Azure Command-Line Interface (Az CLI) to create and manage resources on Azure.
If you don't have the Az CLI installed on your machine, you can follow the steps from the official documentation to install it.
It's very easy and you can use the CLI from Windows, Mac or Linux.
This is one of the reasons why I prefer the Az CLI instead of PowerShell.
Installation Guide

After the installation you can login on your Azure Tenant with the command:

az login
Enter fullscreen mode Exit fullscreen mode

Publish and Zip the application

First of all, we need to publish the application and create a zip file with all the binaries.
Let's do that with the following commands:

dotnet publish -o publish
cd .\publish
Compress-Archive . publish.zip
Enter fullscreen mode Exit fullscreen mode

Compress-Archive is a PowerShell command. If you are using the Az CLI from another OS, you can find the right way to create a zip file for folder from the command line.

Execute the deployment

Now you are ready to deploy the web application with the zip deploy.
From the publish folder, you can launch the following script:

az webapp deployment source config-zip --src .\publish.zip -n "appServiceName" -g "resourceGroupName"
Enter fullscreen mode Exit fullscreen mode

Remember to replace the appServiceName and the resourceGroupName placeholders with your right values for these two parameters.
If you are using PowerShell you can also create two variables before that line. It's more clear and easier to maintain.

$appServiceName = "app_service_name"
$resourceGroupName = "resource_group_name"

az webapp deployment source config-zip --src .\publish.zip -n $appServiceName -g $resourceGroupName

Enter fullscreen mode Exit fullscreen mode

If everything works, you see the result of the activities after a while, directly in the console.

az CLI deploy

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player