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
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
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"
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
If everything works, you see the result of the activities after a while, directly in the console.
Top comments (3)
What to do if everything works as described and I end up with "You do not have permission to view this directory or page." when opening the webpage?
Do you compress the content of the publish folder and not the parent folder?
I do run the Compress cmdlet while in the publish folder. I end up having a publish folder in the wwwroot folder on my Azure resource.
Edit:
Found the solution. While in the publish folder the cmdlet that worked would be: Compress-Archive * publish.zip