SonarCloud Prepare fails for .NET 5 project

I’m running into an issue after porting my project from .NET Core 3.1 to .NET 5.
Since then, my Azure DevOps build is failing on the “SonarCloud Prepare” step, version 1.20.0 with the following error:

##[error]It was not possible to find any compatible framework version
It was not possible to find any compatible framework version
##[error]The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      5.0.7 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=ubuntu.20.04-x64
The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      5.0.7 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=ubuntu.20.04-x64
##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 150

However, there’s not a single reference to the Microsoft.NETCore.App in version 2.0.0.
I’m confused where that error is comming from. Every project is referencing version 5.0.0.

I’m using the latest Azure DevOps extension version in the build.
The pipeline is running on ubuntu-20.04, with the latest .NET 5 SDK.

1 Like

Hi @Herdo , welcome to the community.

I would guess that this message comes from either the Prepare SonarCloud configuration or Run Code Analysis.

Using the Azure DevOps extension, there are only the .NET Core 2 flavor of the Scanner for .NET available, and i think this is the reason why you get this message.

Before being smart enough to detect which version we should run, one workaround would be to execute the “Use DotNet” task before each of our task, and target .NET Core 2 SDK.

If you are using ubuntu hosted image, the version 2.1 should be accessible and picked up, otherwise you’ll need to install it beforehand.

HTH,
Mickaël

Thanks @mickaelcaro - adding the latest 2.x runtime manually does the job as a workaround.
However, the .NET Core 2.1 version is leaving LTS in roughly two months.
Are there any plans to move the Azure DevOps extension scanner for .NET for .NET 5?
If not, what is the recommended way to use SonarCloud in Azure DevOps?

We already provide more recent flavor of the Scanner for .NET (.NET Core 3 and .NET 5), but they are not shipped yet within the SonarCloud extension.

So you can still manually run this Scanner with a batch command.

1 Like

Is this still the case with sonar cloud extension? we are looking at wanting to use dotnet 5
how would I call the scanner with batch command? can you post an example?
Thanks!

Hi @Tom_Wilson

You can find some examples on our documentation just here

HTH,
Mickaël

A post was split to a new topic: Support for .NET 6

Closing this topic, as both .NET 5 and .NET 6 are supported.