Deploy ASP.NET framework Web App to Azure using Azure DevOps
This is not a new topic, but somehow I faced some challenges around it, and I will bring here a solution.
Create a Sample Application (if you don’t have one)
To create this sample ASP.NET framework application (!!not .Net CORE!!), I used this tutorial from Microsft, using the 4.8 framework version: Quickstart: Deploy an ASP.NET web app — Azure App Service | Microsoft Learn
**** One trick here, to deploy it manually to your subscription, you need to enable “Basic Authentication”:
The Azure DevOps YAML pipeline
The challenge here is to keep it simple, using the “AzureWebApp” action. I was having an error: “Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task”
So I realized from this documentation that I needed to compress the package for myself (not during build): https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-web-app-v1?view=azure-pipelines&viewFallbackFrom=azure-devops
This is the final solution is here:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl="$(Agent.TempDirectory)\WebAppContent\\"
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: ArchiveFiles@2
displayName: Archive Files
inputs:
rootFolderOrFile: $(Agent.TempDirectory)\WebAppContent
includeRootFolder: false
- task: AzureWebApp@1
inputs:
azureSubscription: 'service connection name'
appType: 'webApp'
appName: 'your web app name'
package: '$(build.artifactstagingdirectory)/**/*.zip'
deploymentMethod: 'auto'