如何使用SonarQube的C#插件设置FxCop安装路径

时间:2014-05-23 06:36:46

标签: c# sonarqube sonar-runner

我正在尝试使用SonarQube C#插件分析.NET C#项目。 从C#Plugin 3.0开始,在sonar-project.properties中自动执行FxCop“sonar.fxcop.mode = skip”,所以我将FxCop安装到以下目录。

C:\Program Files (x86)\Microsoft FxCop 1.35

当我从Jenkins的声纳插件中运行SonarQube Runner时,我得到了以下错误。

ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: The property "sonar.cs.fxcop.assembly" must be set.
ERROR: 
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure
Finished: FAILUR

我在SonarQube上启用了Visual Studio Bootstrapper,我再次运行了SonarQube Runner,然后出现了以下错误。

ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: java.io.IOException: Cannot run program "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Static Analysis Tools/FxCop/FxCopCmd.exe": CreateProcess error=2, ?w?????t?@?
ERROR: Caused by: Cannot run program "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Static Analysis Tools/FxCop/FxCopCmd.exe": CreateProcess error=2, ?w?????t?@?
ERROR: Caused by: CreateProcess error=2, ?w?????t?@?
ERROR: 
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

我将“sonar.fxcop.installDirector = C:/ Program Files(x86)/ Microsoft FxCop 1.35”添加到sonar-project.properties,然后再次运行SonarQube Runner,但发生了同样的错误。

我想如果禁用了Visual Studio Bootstrapper并且sonar-project.properties正确指定了“sonar.cs.fxcop.assembly”和“sonar.fxcop.installDirector”,那么它工作正常,但我不想指定很多属性在sonar-project.properties。

如何通过启用Visual Studio Bootstrapper来设置FxCop执行路径?

环境:

  • SonarQube4.2
  • SonarQube的C#插件3.0
  • SonarQube Runner 2.4

sonar-project.properties

sonar.projectKey=xxxxx
sonar.projectVersion=1.0
sonar.projectName=Project Name

sonar.language=cs
sonar.dotnet.key.generation.strategy=safe
sonar.sourceEncoding=UTF-8

# This property is set because it is required by the SonarQube Runner.
# But it is not taken into account because the location of the source
# code is retrieved from the .sln and .csproj files.
sonar.sources=.
sonar.fxcop.mode=skip
sonar.gendarme.mode=skip
sonar.gallio.mode=skip
sonar.ndeps.mode=skip
sonar.stylecop.mode=skip
sonar.fxcop.installDirector=C:/Program Files (x86)/Microsoft FxCop 1.35

此致

2 个答案:

答案 0 :(得分:3)

这里的问题相同。我认为在安装Visual Studio Bootstrapper之后,您需要设置以下密钥以匹配FxCop可执行文件的路径:

sonar.cs.fxcop.fxCopCmdPath

默认情况下,它具有您在第二个错误日志中提到的值。

答案 1 :(得分:2)

我找到了这个问题的解决方案,在声纳qube上作为管理登录然后进入设置,在常规设置下找到Category,选择C#然后单击Code Analysis / FxCop选项卡,然后找到“FxCopCMD.Exe的路径” “并按示例

中的建议添加FXCopCMD.exe的完整路径

click on this to see image and process