【问题标题】:How to use FxCop analysis with the new MsBuild Sonar runner?如何将 FxCop 分析与新的 MsBuild Sonar 运行器一起使用?
【发布时间】:2015-11-15 12:38:47
【问题描述】:

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

我遇到的最后一个问题是进行 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 开始

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:

MSBuild.exe targets.msbuild ...

  1. ReSharper 分析:

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

  1. 赛跑者终点:

MSBuild.SonarQube.Runner.exe end

【问题讨论】:

  • 或者使用新的跑步者,FxCop 报告必须手动生成,类似于 ReSharper 报告?
  • 不,FxCop 应该在 MSBuild 期间强制执行 - 也就是说,除非您对 .csproj 和 MSBuild 文件进行了大量自定义 - 是这样吗?
  • 您可以删除未使用的属性:sonar.cs.fxcop.fxCopCmdPath, sonar.visualstudio.solution, sonar.visualstudio.testProjectPattern
  • 也许尝试做一个完整的 MSBuild 重建,并发送日志

标签: msbuild sonarqube fxcop sonar-runner sonarqube-msbuild-runner


【解决方案1】:

我建议升级到新发布的 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.testProjectPatternsonar.dotnet.excludeGeneratedCodesonar.cs.fxcop.fxCopCmdPathsonar.visualstudio.solutionsonar.dotnet.buildConfigurations

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

对于 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,当您的质量配置文件中启用 FxCop 规则时,它将在 msbuild 期间执行。

【讨论】:

  • 嗨@Dinesh - 如果我从 TeamCity 运行 SonarQube,我应该在 TeamCity 服务器上安装 FxCop 吗?
  • FxCop 随 Visual Studio 一起提供。如果您想在 SonarQube 分析中运行 FxCop 规则,那么是的,您应该将它安装在您的构建机器上。但是,如果您禁用所有 FxCop 规则,则不需要安装它。
猜你喜欢
  • 2016-12-12
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 2020-04-08
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 2014-07-07
相关资源
最近更新 更多