Building .NET 7 Apps using Azure DevOps

Building .NET 7 Apps using Azure DevOps

I’ve been using .NET7 for a little while now. I’ve only recently tried to build any of those projects using an Azure CI/CD pipeline. One of the things I had to work around was the fact that .NET7 doesn’t exists on the Azure build servers, at least by default. You have to install it first. Here’s the bit of YAML that did that, for me:

- task: UseDotNet@2
  displayName: 'install .NET 7.x'
    packageType: 'sdk'
    version: '7.x'
    includePreviewVersions: true

Then just build normally.

Testing was also an issue, since my old .NET Core test block wouldn’t work for a .NET7 solution. Here’s the YAML I use for testing, now:

- task: VSTest@2
  displayName: 'test code'
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
    searchFolder: '$(System.DefaultWorkingDirectory)'
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

By the way, my variables section looks like this, in case you were wondering:

  solution: 'src/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

That’s it! Hopefully this will help anyone who is trying to get a .NET 7.x project to build using Azure DevOps.

Photo by Waldemar Brandt on Unsplash