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.
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
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.
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.
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>
.NET framework ($(ScannerNetFxVersion) ) is not supported for dotnet tools and has to be removed from <TargetFrameworks ../> from C# projects property.