Table of Contents

Starting with .Net in Azure DevOps

Summary: In this post I'll create an Azure VM with Visual Studio Community installed, and use that to generate a sample .Net Core application so we can test builds and deployments with Azure DevOps.
Date: Around 2021
Refactor: 21 February 2025: Checked links and formatting.

Create Azure VM with Visual Studio

Create the Virtual Machine

Enable Bastion

Note: Bastion is expensive, disable and recreate the Bastion service every time you need it.

Install Visual Studio Community

From the links below download and install Edge Chromium (optional) and Visual Studio Community. During the installation of Visual Studio make sure to install the “ASP.NET and web development” workload. After the installation, Visual Studio starts, and asks to sign in, which you can also skip.

Note that during the installation you have plenty of time, so continue with the configuration of Azure DevOps and repository below

Configure Azure DevOps Project and Repository

In your Azure DevOps Organization create a new project:

Create a .Net Sample App

In the newly installed Visual Studio, click “Create a new project”

Push to Azure DevOps

Once the project is created, go to Git and click Create Git Repository

Note that you might have to commit the new files to the repository before they get pushed to azure devops.

Run a Build

Now the files are in Azure DevOps we can create a build. From the repository you can directly click “Set up build”. This will already setup the build to use the repository from where you are, so you can start with configuring the pipeline immediately. Select the ASP.NET Core pipeline, which will automatically create a YAML pipeline

asp.net pipeline

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
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:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Create Azure Web App

To deploy the web app we need to have an Azure Web App.

Note that if you'd go to the Web App website, in this case, https://az400.azurewebsites.net/ , you'll now see the default deployment page telling you to upload you code.

Create a Release

Now that we have a successful build and an Azure Web App we can deploy the web application to Azure. In Azure DevOps, go to Releases and click “New Pipeline”

Once the release is finished you can go to the url of the web app, https://az400.azurewebsites.net/ , and see your .net web application running.

Resources

Resources: