Analyze mixed versions of .NET

  • which versions are you using

    • SonarQube
      • 8.5 Community
    • Scanner
      • sonar-scanner-msbuild-4.10.0.19059-net46
      • sonar-scanner-msbuild-5.1.0.28487-net5.0
  • what are you trying to achieve
    In a single git repository we have two .NET 5 solutions and one .NET 4.7.2 solution and one .NETStandard 2.0 solution. The .NETStandard project is referenced by all other .NET projects (.NET 5 & .NET 4.7.2)

     /MyGitRepo
        /Common Solution
    		/Common.csproj (NetStandard 2.0)
       /Solution1 (.NET 5)
            All projects are .NET5 
            References Common.csproj
      /Solution2 (.NET 5)
    	    All projects are .NET5 
          References Common.csproj
     /Solution3 (.NET Framework 4.7.2)
    	    All projects are 4.7.2 
          References Common.csproj
    

I understand that .Net 4.7.2 and .Net 5 have different scanners. I would like to know, If I analyze solutions using their respective scanners but point both scanners to the same SonarQube project using same project key in both scanners, will it work? or will the second scans overwrite the result of the first scan?

--Scan NET 5 solutions
dotnet "C:\SonarQubeScanners\net5\SonarScanner.MSBuild.dll" begin /k:"MyProjectKey" /d:sonar.host.url="http://sonarqube.xyz.com" /d:sonar.login="myloginkey"
dotnet build Solution1.sln"
dotnet build Solution2.sln"
dotnet "C:\SonarQubeScanners\net5\SonarScanner.MSBuild.dll" end /d:sonar.login="myloginkey"

--Scan NET 4.7.2 solution
C:\SonarQubeScanners\net46\SonarScanner.MSBuild.exe begin /k:"MyProjectKey" /d:sonar.host.url="http://sonarqube.xyz.com" /d:sonar.login="myloginkey"
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" "Solution3.sln" /t:Rebuild /p:Configuration=Release 
C:\SonarQubeScanners\net46\SonarScanner.MSBuild.exe end /d:sonar.login="myloginkey"

I am trying to avoid creating two separate SonarQube projects, One for .NET 5 solutions and Second for .NET 4.7.2 Solution.

Hi @LP2020

First of all, please accept my apologies for the late answer.

With the example you submitted the second scan would override the results of the first one.

To see all the results without creating two separate projects you can do the following:

dotnet "C:\SonarQubeScanners\net5\SonarScanner.MSBuild.dll" begin /k:"MyProjectKey" /d:sonar.host.url="http://sonarqube.xyz.com" /d:sonar.login="myloginkey"
dotnet build Solution1.sln
dotnet build Solution2.sln
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" "Solution3.sln" /t:Rebuild /p:Configuration=Release
dotnet "C:\SonarQubeScanners\net5\SonarScanner.MSBuild.dll" end /d:sonar.login="myloginkey"

All the best,
Čaba