0

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)
Zhanglong Wu - MSFT
  • 1,652
  • 1
  • 7
  • 8
Zeno
  • 581
  • 1
  • 7
  • 23
  • Please check if the folder has permission to write the file in it. – Zhanglong Wu - MSFT Dec 26 '16 at 02:46
  • xxc3zd2a.tmp_proj seems to be a temporary or auto generated project. Can you exclude it from the analysis? Add `true` to the project properties. The `.RoslynCA.json` is the SARIF json file generated by roslyn. We try to put it next to the generated exe/dll. Maybe this is a customized msbuild project that doesn't generate the expected folder. If that's the case, then as a workaround, you can add a task before the CoreCompile target to create the folder. – Tamas Jan 04 '17 at 14:19

1 Answers1

1

This issue has been resolved by editing the csproj file for the main project in our solution. It initially looked like this:

<OutputPath>$(BuildOutputPath)\bin\$(MSBuildProjectName)\$(Configuration)</OutputPath>

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...

Zeno
  • 581
  • 1
  • 7
  • 23
  • FYI this is now being tracked by [this GitHub issue](https://github.com/SonarSource/sonar-scanner-msbuild/issues/513). It looks like the problem is only with WPF projects. – duncanp May 25 '18 at 16:00
  • Issue is fixed with Scanner for MSBuild 4.3+ – Amaury Levé Jun 05 '18 at 08:31