Azure Pipelines: Fixing 'The project was restored using Microsoft.NETCore.App version x.x.x'
I couldn't find an answer for this anywhere, and other people are hitting it too, so here's a quick post.
It started with a library conflict: the pipeline couldn't work out
which package to restore. Explicitly setting a version for the
Microsoft.AspNetCore.App package fixed that, despite going
against best practice.
Then came this error:
Error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 1.0.0, but with current settings, version 2.2.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.
Some people fixed it by targeting the latest runtime in their projects. For me, the pipeline still wanted to restore using 1.0.0.
Solution
If you're using the default YAML build script, the generic one the pipeline generates after detecting your project type, that script is the problem.
Replace
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'with:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'With many projects in your solution, this may add a fair amount of time to the build, but that wasn't an issue for me.
An even easier solution

The classic editor gives you a visual pipeline of build tasks that gets you 90% of the way by default. Without any changes, it almost fully built my default .NET Core SPA.
Honestly, I'm a little disappointed in the new YAML builder. A version-controlled build script is nice, but a lot of people are having problems, especially people new to .NET, who shouldn't have to spend hours getting a vanilla .NET Core app to deploy to a branch or staging site.