带有 SonarQube 的 TeamCity for Code Analysis 构建失败

TeamCity with SonarQube for Code Analysis build fails

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# 功能。

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

已编辑

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

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 Studio17\BuildTools\MSBuild.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) 抛出的。

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

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

从日志输出来看,您使用的 MSBuild 扫描程序版本早于 MSBuild 15 的发布,因此文件不会被复制到 MSBuild15 特定的位置。这将导致 "no ProjectInfo.xml files were found" 状态。

如果扫描器日志中的警告消息明确列出受支持的 MSBuild 版本范围会更好,例如"This version of the Scanner supports MSBuild v12.0 to v14.0"。我创建了 issue #502 来跟踪这个。