3

我正在尝试在 .NET 项目中从旧的声纳运行器迁移到新的 MsBuild 声纳运行器。

我遇到的最后一个问题是进行 FxCop 分析。如果 Sonar 中的质量配置文件包含任何 FxCop 规则,我会收到以下构建错误:

ERROR: Caused by: The property "sonar.cs.fxcop.assembly" must be set and the project must have been built to execute FxCop rules.
This property can be automatically set by the Analysis Bootstrapper for Visual Studio Projects plugin, see: http://docs.codehaus.org/x/TAA1Dg.
If you wish to skip the analysis of not built projects, set the property "sonar.visualstudio.skipIfNotBuilt".

我搜索了很多,发现了一些具有相同问题的相当古老的主题,但没有一个解决方案有效。
我尝试添加sonar.visualstudio.enable="true"参数,但随后出现以下错误:

ERROR: Caused by: Do not use the Visual Studio bootstrapper and set the "sonar.modules" property at the same time.

也尝试添加/d:sonar.visualstudio.skipIfNotBuilt="true",但没有帮助。

我究竟做错了什么?如何参数化新的 MsBuild 声纳运行器以使 FxCop 分析工作?

这些是我正在执行的命令(我修改了文件名和路径):
1. Sonar runner begin

MSBuild.SonarQube.Runner.exe begin /key:"MyProject" /name:"MyProject"
/version:"1" /d:sonar.host.url="http://mysonarhost/" /d:sonar.jdbc.dialect="mssql"
/d:sonar.jdbc.url="jdbc:jtds:sqlserver://mysonardb" /d:sonar.jdbc.username="sonar-user"
/d:sonar.jdbc.password="sonar-password" /d:sonar.resharper.cs.reportPath="../../../../resharperresults.xml"
/d:sonar.resharper.solutionFile="MySolution.sln"
/d:sonar.visualstudio.testProjectPattern=".*\.(UnitTests|IntegrationTests)"
/d:sonar.exclusions="obj/**" /d:sonar.dotnet.excludeGeneratedCode="true"
/d:sonar.cs.fxcop.fxCopCmdPath="..\Tools\FxCop.v12.0.21005.1\FxCopCmd.exe"
/d:sonar.visualstudio.solution="MySolution.sln" /d:sonar.dotnet.buildConfigurations="Release"
/d:sonar.language="cs" /d:sonar.sourceEncoding="UTF-8"
/d:sonar.cs.opencover.reportsPaths="..\CodeCoverage\MSTest.Coverage.MySolution.UnitTests.xml"
  1. 构建:

MSBuild.exe targets.msbuild ...

  1. ReSharper 分析:

inspectcode.exe /o=resharperresults.xml MySolution.sln

  1. 赛跑者结束:

MSBuild.SonarQube.Runner.exe end

4

1 回答 1

0

我建议升级到新发布的 MSBuild SonarQube Runner 版本 1.0.1,这将强制禁用 Visual Studio Bootstrapper 插件。迁移所有项目以使用 MSBuild SonarQube Runner 后,应从 SonarQube 服务器卸载 Visual Studio Bootstrapper 插件。

然后,所有 SonarQube 服务器和 JDBC 属性(例如sonar.host.urlsonar.jdbc.url)都通过SonarQube.Analysis.xml文件传递而不是通过命令行传递。

以下属性是无用的:sonar.visualstudio.testProjectPattern, sonar.dotnet.excludeGeneratedCode, sonar.cs.fxcop.fxCopCmdPath, sonar.visualstudio.solution,sonar.dotnet.buildConfigurations

sonar.language可以删除,因为自 SonarQube 4.2 版起 SonarQube 支持多语言项目。

对于 OpenCover,请查看:http ://docs.sonarqube.org/display/PLUG/C%23+Code+Coverage+Results+Import#C#CodeCoverageResultsImport-OpenCover

对于 ReSharper,位于:http ://docs.sonarqube.org/display/PLUG/ReSharper+Plugin

FxCop 是本机支持的,它的执行将msbuild在您的质量配置文件中启用 FxCop 规则期间发生。

于 2015-09-11T10:08:26.850 回答