SonarScanner does not support .NET 6.0 (LTS) sdk/runtime

The current SonarScanner for .NET version does not support net6.0 and Azure DevOps build pipeline fails without additional net3.1 or net5.0 runtime. See build log excerpt.

(related .NET 6 and C#10 support update - SonarSource Updates / Announcements - SonarSource Community)

Starting: Prepare analysis on SonarQube

==============================================================================

Task : Prepare Analysis Configuration

Description : Prepare SonarQube analysis configuration

Version : 5.0.0

Author : sonarsource

Help : Version: 5.0.0. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)

==============================================================================

/opt/hostedtoolcache/dotnet/dotnet /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/5.0.0/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll begin /k:TP-PM.MI.PullPlugin

##[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 '3.1.0' (x64) was not found.

- The following frameworks were found:

5.0.12 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

6.0.0 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=3.1.0&arch=x64&rid=ubuntu.20.04-x64

The framework 'Microsoft.NETCore.App', version '3.1.0' (x64) was not found.

- The following frameworks were found:

5.0.12 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

6.0.0 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=3.1.0&arch=x64&rid=ubuntu.20.04-x64

##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 150

Finishing: Prepare analysis on SonarQube

see source file: sonar-scanner-msbuild/DotnetVersions.props at 5.3.2.38712 · SonarSource/sonar-scanner-msbuild · GitHub

By the way, .NET Core 2.1 reached end of support on August 21, 2021

2 Likes

Hi @Bertk

Are you using the UseDotNet task by chance ?

Mickaël

Hi @mickaelcaro,

yes, we use this task since some months for a workaround but we need to get the .NET 6.0 support and remove this. We plan the migration to .NET 6.0 in the next weeks with a 3 digits number of CI build pipelines. Removing the workaround is an additional effort for all teams.

- task: UseDotNet@2
  displayName: 'Use global dotnet sdk'
  inputs:
    packageType: 'sdk'
    useGlobalJson: true

- task: UseDotNet@2
  displayName: 'Use runtime 3.x'
  inputs:
    packageType: 'runtime'
    version: '3.x' # needed for "Prepare analysis on SonarQube"

Do you have an idea why this is not possible to use .NET 5.0 instead of .NET Core 3.1?

Problem is UseDotNet task hides all accessible / installed version of the .NET SDK on the machine.

Azure DevOps extension for SonarCloud still relies on the .NET Core 3.1 version (so this one needs to be installed and available).

It doesn’t mean that this one will not be compatible with .NET 6 code, we’re just speaking compilation and runtime of the scanner itself here.

HTH,
Mickaël

We have a different experience with other dotnet tools e.g. cyclonedx or dotnet-reportgenerator-globaltool and this tools run on net6.0, net5.0, netcore3.1, …

SonarScanner requires .NET Core 3.1 and hopefully this limitation is removed and it supports .NET 6.0 soon.

Yep an update will follow soon :wink:

@mickaelcaro I found the branch net6-support and have some suggestions.

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <PropertyGroup>
    <ScannerNetStandardVersion>netstandard2.0</ScannerNetStandardVersion>
    <ScannerNetCoreVersion>netcoreapp3.1</ScannerNetCoreVersion>
    <ScannerNetFxVersion>net48</ScannerNetFxVersion>
    <ScannerNetVersion>net6.0;net5.0</ScannerNetVersion>
  </PropertyGroup>
</Project>

Some newer MSBuild nuget packages have to be used for this e.g. V15.9.20 or newer

    <PackageReference Include="Microsoft.Build" Version="15.9.20" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" />
  • The tool package is packed using a nuspec file. This could also be done in the csproj file and you can create the package within Visual Studio and check it with nuget explorer.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>$(ScannerNetCoreVersion);$(ScannerNetVersion)</TargetFrameworks>
    <AssemblyName>SonarScanner.MSBuild</AssemblyName>
    <OutputType>Exe</OutputType>
    <RollForward>LatestMajor</RollForward>
    <Title>SonarScanner for .Net Core</Title>
    <Description>The SonarScanner for .Net Core from version 3.1 allows easy analysis of any .NET project with SonarCloud/SonarQube.</Description>
    <PackageId>dotnet-sonarscanner</PackageId>
    <PackageIconUrl>https://cdn.rawgit.com/SonarSource/sonar-scanner-msbuild/cdd1f588/icon.png</PackageIconUrl>
    <PackageVersion>5.4.0</PackageVersion>
    <PackageTags>sonarqube sonarcloud msbuild scanner sonarsource sonar sonar-scanner sonarscanner</PackageTags>
    <PackageLicenseFile>License.txt</PackageLicenseFile>
    <PackageReleaseNotes>
All release notes for SonarScanner .Net Core can be found on the GitHub site - https://github.com/SonarSource/sonar-scanner-msbuild/releases
    </PackageReleaseNotes>
    <PackAsTool>true</PackAsTool>
    <ToolCommandName>dotnet-sonarscanner</ToolCommandName>
    <PackageOutputPath>./nupkg</PackageOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <None Include="SonarQube.Analysis.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <SubType>Designer</SubType>
    </None>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SonarScanner.MSBuild.Common\SonarScanner.MSBuild.Common.csproj" />
    <ProjectReference Include="..\SonarScanner.MSBuild.PostProcessor\SonarScanner.MSBuild.PostProcessor.csproj" />
    <ProjectReference Include="..\SonarScanner.MSBuild.PreProcessor\SonarScanner.MSBuild.PreProcessor.csproj" />
    <ProjectReference Include="..\SonarScanner.MSBuild.Shim\SonarScanner.MSBuild.Shim.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="Resources.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Update="Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

  <ItemGroup>
      <None Include="License.txt" Pack="true" PackagePath="%(FileName)%(Extension)" />
      <None Include="$(MSBuildThisFileDirectory)..\SonarScanner.MSBuild.Tasks\scripts\**\*.targets">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <PackagePath>%(RecursiveDir)\%(FileName)%(Extension)</PackagePath>
      <None Include="$(MSBuildThisFileDirectory)..\..\sonar-scanner-cli\**\*.*">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <PackagePath>%(RecursiveDir)\%(FileName)%(Extension)</PackagePath>
      </None>
      </None>
  </ItemGroup>
</Project>

I also added some properties in Directory.Build.props

<PropertyGroup>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisLevel>latest</AnalysisLevel>
  </PropertyGroup>

  <PropertyGroup>
    <!-- see  https://docs.microsoft.com/en-us/dotnet/core/tools/csproj -->
    <!-- also https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target -->
    <copyright>SonarSource SA and Microsoft Corporation</copyright>
    <Authors>SonarSource,Microsoft</Authors>
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <IncludeSource>false</IncludeSource>
    <!-- Optional: A URL for the project homepage or source repository.-->
    <PackageProjectUrl>http://redirect.sonarsource.com/doc/msbuild-sq-runner.html</PackageProjectUrl>
    <!--Optional: Source Link automatically adds RepositoryUrl and RepositoryType metadata to the NuGet package-->
    <RepositoryUrl>https://github.com/SonarSource/sonar-scanner-msbuild</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <!-- Optional: Embed source files that are not tracked by the source control manager in the PDB -->
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    <!-- Optional: Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>    
  </PropertyGroup>
2 Likes

Hey @Bertk

Thanks for the suggestion, i redirected them to the team.

Mickaël

@mickaelcaro Thanks. I missed on point

  • .NET framework ($(ScannerNetFxVersion) ) is not supported for dotnet tools and has to be removed from <TargetFrameworks ../> from C# projects property.

Did some more updates :wink:

I used a debug build

Hi @Bertk

Until we release a new scanner version, you can use this workaround:

        env:
          DOTNET_ROLL_FORWARD: Major
1 Like

Hi @Andrei_Epure,
thank you for the hint. I will use this for the Azure DevOps CI.
I hope the new release is available until 3rd December

By the way, there are still some issues reported by Visual Studio.

@mickaelcaro @Andrei_Epure
Hi,
are there any plans deprecating .NET framework scanner? or do you update the .NET framework version to 4.7.2 or 4.8?
NuGet Gallery | dotnet-framework-sonarscanner 5.2.0

Hi @Bertk

This package is not maintained or published by SonarSource. You should ask its maintainer - GitHub - Roemer/nuget-packages

These are the official SonarSource nugets: NuGet Gallery | SonarSource

1 Like

@Andrei_Epure Sorry Andrei, I missed that.

Meanwhile I used successfully the workaround in one of the Azure YAML build pipelines.

variables:
- name: 'DOTNET_ROLL_FORWARD'
  value: 'Major'
2 Likes

we released a new version of the scanner which supports .NET 6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.