使用SonarQube进行代码分析构建的TeamCity失败

时间:2018-05-21 08:56:30

标签: c# msbuild sonarqube teamcity analysis

许多用户的常见问题是SonarQube代码分析失败并出现错误:

[10:06:05]No ProjectInfo.xml files were found. Possible causes: 
[10:06:05]1. The project has not been built - the end step was called right 
after the begin step, without a build step in between 
[10:06:05]2. An unsupported version of MSBuild has been used to build the 
project. Currently MSBuild 12.0 upwards are supported
[10:06:05]3. The build step has been launched from a different working folder
[10:06:05]Post-processing failed. Exit code: 1
[10:06:05]Process exited with code 1

很多参考文献都说修复是使用MSBuild.exe的完整路径,但是,我使用完整路径,但是我使用MSBuild 15.0版本和最新的C#版本,旧的MSBuild在代码中的新C#功能失败了

然而,我无法摆脱这个错误,我不知道可以做些什么,所以也许你们中的任何一个人已经遇到过这个问题并且可以帮助我?

EDITED

我很确定这些步骤都不应该是失败的原因,第二个步骤只是最接近的一个,因为我的构建步骤是

Team City构建步骤如下所示。

步骤XX:

cd %projectDirectory%
"C:\sonarqube-5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" begin   ... params
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "MyProject.sln" /t:Clean;Rebuild

步骤XY:

...

步骤XZ :(最后一次)

cd %projectDirectory%
"C:\sonarqube-5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" end

对我而言,它看起来非常简单易懂,但我仍然遇到了这个错误而且我不知道为什么,错误会在最后一步(XZ)中抛出。

1 个答案:

答案 0 :(得分:2)

您需要升级到较新版本的Scanner for MSBuild。我建议升级到最新版本(撰写本文时为v4.2)。

扫描程序为MBuild的每个受支持版本在以下位置复制目标文件:%localappdata%\ Microsoft \ MSBuild [MSBuild version] \ Microsoft.Common.targets \ ImportBefore。

从日志输出的外观来看,您使用的是MSBuild扫描程序的版本,它早于MSBuild 15的发布,因此该文件不会被复制到MSBuild15特定的位置。这将导致“未找到ProjectInfo.xml文件”状态。

如果扫描程序日志中的警告消息明确列出了受支持的MSBuild版本范围,则会更好。 “此版本的扫描仪支持MSBuild v12.0至v14.0”。我创建了issue #502来跟踪此事。