.NET Core 3.1 - Build, Test and Deploy CI/CD Pipeline for Azure Web Apps (Linux)

.Net Core 3.1 LTS is available from December so most of you will probably update over time your existing apps in order to benefit for longer support at least until .Net Core 5.0 is available.

If you have not upgraded your projects yet please do so. Also keep an eye on the Microsoft .Net Core release  lifecycles.

VersionOriginal Release DateLatest Patch VersionPatch Release DateSupport LevelEnd of Support
.NET Core 3.1December 3, 20193.1.3March 24, 2020LTSDecember 3, 2022
.NET Core 3.0September 23, 20193.0.3February 18, 2020EOLMarch 3, 2020
.NET Core 2.2December 4, 20182.2.8November 19, 2019EOLDecember 23, 2019
.NET Core 2.1May 30, 20182.1.17March 24, 2020LTSAugust 21, 2021
.NET Core 2.0August 14, 20172.0.9July 10, 2018EOLOctober 1, 2018
.NET Core 1.1November 16, 20161.1.13May 14, 2019EOLJune 27 2019
.NET Core 1.0June 27, 20161.0.16May 14, 2019EOLJune 27 2019

If you are creating now a new project or just upgrading an old one, you will want to have it on a CI/CD pipeline in Azure in order to speed up deployment and also automate the whole end to end process.

Bellow you will find a basic YAML configuration in order to get you started.

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

#set the trigger to the branch you want to use for Continous Integration
trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:

#The default build container still comes by default with .net core 2.2
#Make sure you use the need version and apply it bellow. use 3.1.x for latest
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.1.x'

#Build the source code
- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: 'build'
    projects: "**/*.sln"
    arguments: '--configuration $(buildConfiguration)'

#run Tests
- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'


#If you have only one web project you can remove the Project variable and use publishWebProjects: true
#In case you have a more advanced setup I recoomed specifying projects path
- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: 'publish'
    projects: "**/*.sln"
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True


#Upload the generated artifact to the pipeline history
- task: PublishBuildArtifacts@1
  displayName: Upload artifact
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
    artifactName: 'Your-Artifact-Name'

#Deploy to Azure Web APP
- task: AzureRmWebAppDeployment@4
  displayName: Deploy
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Service-connection-name'
    appType: 'webAppLinux'
    WebAppName: 'Your-WebApp-Name'
    packageForLinux: '$(System.ArtifactsDirectory)/**/*.zip'

Make sure you have an Azure Resource Manger connection to your subscription in /_settings/adminservices from your dev.azure.com project URL and replace the value above in azureSubscription with the service “Service connection name” you create. Also change the WebAppName to the name of your web app from Azure

After you run the pipeline, if there are no errors you should also be able to see the status of the deployment in Deployment Center of your web app.