I am trying to analyze my C# code with SonarQube Scanner for MSBuild from command line.
I have installed the SonarQube Scanner for MSBuild 2.2.0.24 (http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild) and have all the prerequisites.
I am running the following commands:
SonarQube.Scanner.MSBuild.exe begin /k:"MyProject" /n:"My Project" /v:"1.0.0.0"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:Rebuild
SonarQube.Scanner.MSBuild.exe end
But when I run msbuild on my solution (.Net Framework 4.5.1) the build fails. The solution builds successfully when I am not doing Sonar scan so it must have something to do with the sonar scanner plugin.
In SonarQube.Analysis.xml I have only provided sonar.host.url, sonar.login and sonar.password.
This is the output from the msbuild:
Build FAILED.
"C:\git\src\MySoltion.sln" (Rebuild target) (1) ->
"C:\git\src\\MyProject\MyProject.csproj" (Rebuild target) (2) ->
"C:\git\src\\MyProject\xxc3zd2a.tmp_proj" (_CompileTemporaryAssembly target) (4) ->
(CoreCompile target) ->
CSC : error CS0016: Could not write to output file 'C:\git\src\\MyProject\Build\bin\xxc3zd2a\Debug\MyProject.exe
.RoslynCA.json' -- 'Could not find a part of the path 'C:\git\src\\MyProject\Build\bin\xxc3zd2a\Debug\MyProject.ex
e.RoslynCA.json'.' [C:\git\src\MyProject\xxc3zd2a.tmp_proj]
0 Warning(s)
1 Error(s)
This issue has been resolved by editing the csproj file for the main project in our solution. It initially looked like this:
But the $(MSBuildProjectName) variable did seem to work when running msbuild during Sonar scan, it generated the
xxc3zd2a.tmp_proj folder, instead of the actual project name. When replacing
$(MSBuildProjectName) with the project name it worked. Our solution has 4 project but I only changed one of them.
Note that when only running msbuild no changes to csproj file is needed...