SonarScanner for MSBuild Integration Failed on C# project

Hi all,
I am trying to use SonarScanner to build and send my results to a remote SonarQube server however I am having issues completing the process.

On the documents for SonarScanner for .NET there are 2 options:

SonarScanner.MSBuild.exe begin /k:"project-key" /d:sonar.login="<token>"
MSBuild.exe <path to solution.sln> /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="<token>"


dotnet <path to SonarScanner.MSBuild.dll> begin /k:"project-key" /d:sonar.login="<token>"
dotnet build <path to solution.sln>
dotnet <path to SonarScanner.MSBuild.dll> end /d:sonar.login="<token>" 

However for [sonar-scanner-msbuild-] there is no MSBuild.exe and thus I am using a combination of the both options to build my program. Testing with a simple C# Hello World program only. My command for starting and ending is as below:

dotnet "...\Desktop\dotnetInstallers\sonar-scanner-msbuild-\SonarScanner.MSBuild.dll" begin /k:"testing1" /d:sonar.verbose=true

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" /t:Rebuild "...\source\repos\TestHelloWorld\TestHelloWorld.sln"

dotnet "...\Desktop\dotnetInstallers\sonar-scanner-msbuild-\SonarScanner.MSBuild.dll" end 

The Begin and Build process completes without any errors however the End process throws an error below:

SonarScanner for MSBuild 5.2.1
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
09:23:48.739  09:23:48.739  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
09:23:48.74  Loading the SonarQube analysis config from C:\WINDOWS\system32\.sonarqube\conf\SonarQubeAnalysisConfig.xml
09:23:48.741  Not running under TeamBuild
09:23:48.741  Analysis base directory: C:\WINDOWS\system32\.sonarqube
Build directory: 
Bin directory: C:\WINDOWS\system32\.sonarqube\bin
Config directory: C:\WINDOWS\system32\.sonarqube\conf
Output directory: C:\WINDOWS\system32\.sonarqube\out
Config file: C:\WINDOWS\system32\.sonarqube\conf\SonarQubeAnalysisConfig.xml
09:23:48.743  Generating SonarQube project properties file to C:\WINDOWS\system32\.sonarqube\out\
09:23:48.747  Generation of the sonar-properties file failed. Unable to complete the analysis.
09:23:48.75  Writing processing summary to C:\WINDOWS\system32\.sonarqube\out\ProjectInfo.log

09:23:48.746  The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
09:23:48.752  Post-processing failed. Exit code: 1

Any idea what I can do to get this running?

Versions List:

  • SonarQube : Developer Edition 8.5.1 Build(38104)
  • SonarScanner : sonar-scanner-msbuild-
  • MSBuild : MSBuild 16.0 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe

Hi @PeterL

Welcome to our community!

It looks to me that you are executing the commands from the C:\WINDOWS\system32\ folder and the analyzed project is outside it.

Could you please run again the analysis (all 3 commands) from the TestHelloWorld project?

I expect the analysis will work fine this time. If not, could you please run the analysis with debug logging enabled and send us the end step log?

dotnet <path to SonarScanner.MSBuild.dll> begin /k:"project-key" /d:sonar.login="<token>" /d:sonar.verbose=true
dotnet build <path to solution.sln>
dotnet <path to SonarScanner.MSBuild.dll> end /d:sonar.login="<token>" 

If you want to simplify the commands a bit, you can install the dotnet-sonarscanner tool:

dotnet tool install --global dotnet-sonarscanner

and then run

dotnet sonarscanner begin /k:"project name" /d:sonar.login="token" /d:sonar.verbose=true
dotnet build --no-incremental
dotnet sonarscanner end /d:sonar.login="token"