0

我正在尝试从命令行使用SonarQube Scanner for MSBuild分析我的 C# 代码。

我已经为 MSBuild 2.2.0.24 ( http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild )安装了 SonarQube 扫描仪并具备所有先决条件。

我正在运行以下命令:

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

但是当我在我的解决方案(.Net Framework 4.5.1)上运行 msbuild 时,构建失败。该解决方案在我不进行声纳扫描时成功构建,因此它必须与声纳扫描仪插件有关。

在 SonarQube.Analysis.xml 中,我只提供了 sonar.host.url、sonar.login 和 sonar.password。

这是 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)
4

1 回答 1

1

此问题已通过在我们的解决方案中编辑主项目的 csproj 文件得到解决。它最初看起来像这样:

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

但是在声纳扫描期间运行 msbuild 时, $(MSBuildProjectName)变量似乎确实有效,它生成了
xxc3zd2a.tmp_proj文件夹,而不是实际的项目名称。当用它工作的项目名称替换
$(MSBuildProjectName)时。我们的解决方案有 4 个项目,但我只更改了其中一个。

请注意,仅运行 msbuild 时不需要更改 csproj 文件...

于 2017-01-04T20:18:56.837 回答