Analyzing multiple solution C# project using sonar-scanner-MSBuild

Hi Team,

I am using the below configuration:
sonarqube-6.7
sonar-scanner-msbuild-4.3
sonar-scanner-3.2

I want to analyze the project which has different C# modules(different .sln file) but while running,

SonarScanner.MSBuild.exe begin /k : "org.sonarqube:sonarqube-scanner-msbuild" /n : "Project Name" /v : "1.0"

MSBuild.exe /t :Rebuild

SonarScanner.MSBuild.exe end

it’s not picking up any modules as i am running above mentioned command from root directory. So how to configure sonar-scanner-msbuild for multiple solution project?
Thanks in advance!

Hi @vicky,

Please provide the logs of the build and scanner end steps.

Hi @Ammo,

Please find the below details:

For this step MSBuild.exe /t :Rebuild
output:

C:\Users\Administrator\Desktop\Analyzer1\Analyzer1\staging\src>MSBuild.exe /t:Re
build
Microsoft ® Build Engine version 15.8.166+gd4e8d81a88 for .NET Framework
Copyright © Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1003: Specify a project or solution file. The current working
directory does not contain a project or solution file.

For this SonarScanner.MSBuild.exe end
output:

C:\Users\Administrator\Desktop\Analyzer1\Analyzer1\staging\src>SonarScanner.MSBu
ild.exe end
SonarScanner for MSBuild 4.3.1
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at C:\Users\Administrator\Downloads\sonar-scan
ner-msbuild-4.3.1.1372-net46\SonarQube.Analysis.xml
Loading analysis properties from C:\Users\Administrator\Downloads\sonar-scanner-
msbuild-4.3.1.1372-net46\SonarQube.Analysis.xml
Post-processing started.
The SonarQube MSBuild integration failed: SonarQube was unable to collect the re
quired information about your projects.
Possible causes:

  1. The project has not been built - the project must be built in between the b
    egin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Curre
    ntly MSBuild 14.0 and 15.0 are supported
  3. The begin, build and end steps have not all been launched from the same fol
    der
  4. None of the analyzed projects have a valid ProjectGuid and you have not use
    d a solution (.sln)
    sonar-project.properties files are not understood by the SonarScanner for MSBuil
    d. Remove those files from the following folders: C:\Users\Administrator\Desktop
    \Analyzer1\Analyzer1\staging\src
    15:04:07.907 Creating a summary markdown file…
    15:04:07.909 Post-processing failed. Exit code: 1

Well as the build step is saying you are not building anything so of course the analysis cannot succeed. Please fix your build step.

Hi @Ammo,

Thanks for your response! While building it is looking for sln file and as i have already mentioned my project has multiple sln file in different modules so that’s why i am trying from root folder. I tried to build each module seperately but that will create seperate project in sonarqube that i don’t want. While exploring i got to know that msbuild-scanner doesn’t support multiple sln files for same project so can you please help?

I have some trouble to follow you… It would be nice to have some example to understand the scenario you are trying to describe.

This is what I got:

/rootFolder
|-- /solution1
|---- solution1.sln
|---- /project11
|-------- project11.csproj
|---- /project12
|-------- project12.csproj
|-- /solution2
|---- solution2.sln
|---- /project21
|-------- project21.csproj
|---- /project22
|-------- project22.csproj

And you want to analyze all the solutions onto the same SonarQube project.

If that’s the case then that’s just a classic msbuild way (nothing specific to SonarQube):
1/ SonarScanner.MSBuild.exe begin …
2/ msbuild /t:rebuild ./solution1/solution1.sln
3/ msbuild /t:rebuild ./solution1/solution2.sln
4/ SonarScanner.MSBuild.exe end …

Cheers

1 Like

@Ammo Thank you for your response. Yup definitely this will works as we can refer multiple solution while building. Thanks