Solved: "This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.App compatible with netcoreapp2.2."

I've been working on a project using .Net Core 2.2. During the course of development I needed to add an SQL Database project to the solution. Everything was building correctly on my local machin, however, the build started failing when I committed and pushed to Azure Devops. The initial issue was that the SQL Database project cannot be built using dotnet build. I tried solving this by switching to VSBuild in my pipeline, however, this caused a new error "This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.App compatible with netcoreapp2.2."

I was confused since my app was compiling correctly on my local machine, and this was also compiling correctly on my co-workers machine. At first I thought the issue was related to the build agent, however I could also build the app correctly from Visual Studio on the build agent. I also tried switching to a hosted agent, however, this did not solve the problem.

After a number of hours searching for a solution, I stumbled across a suggestion to update the Nuget version being used to execute the pipeline. This suggestion was in a github issue. It turns out that I did not include the step to update Nuget when I changed the azure-pipelines.yml file to build using VSBuild instead of dotnet build. All I needed to do was add the below step as the first step of the pipeline and the issue disappeared.

- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '>=5'
    checkLatest: true

Published in: Troubleshooting