Unit Tests in a .NET 6 project with Azure Pipelines DotNetCoreCLI@2
Today I migrated our project from .NET 5 to .NET 6.
An issue I stumbled upon was the Azure YAML Pipeline throwing an error in the DotNetCoreCLI@2 task with the ‘test’ command:
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '5.0.0' (x64) was not found. - The following frameworks were found:
6.0.0 at [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.AspNetCore.App]
As described in this GitHub issue you have to add the UseDotNet@2 task and select version ‘6.0.x’ which was already the case. Also note that vmImage ‘windows-latest’ still targets 2019, so if you use a Windows vmImage, specify ‘windows-2022’. But I use ‘ubuntu latest’. So this didn’t solve my issue.
This StackOverflow answer did solve my issue. I included a ‘restore’ step and in the ‘test’ step added an argument not to restore.
> The solution that worked for me can be found in this GitHub gist.
Note the following parts: