【问题标题】:How to set FxCop installation path using SonarQube's C# plugin如何使用 SonarQube 的 C# 插件设置 FxCop 安装路径
【发布时间】:2014-07-12 10:01:36
【问题描述】:

我正在尝试使用 SonarQube C# 插件分析 .NET C# 项目。 从 C# Plugin 3.0 开始,即使 sonar-project.properties 中的“sonar.fxcop.mode=skip”,FxCop 也会自动执行,因此我将 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

声纳项目.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

问候

【问题讨论】:

    标签: c# sonarqube sonar-runner


    【解决方案1】:

    我找到了解决这个问题的方法,在 sonar qube 上以管理员身份登录,然后转到设置,在常规设置下找到类别,选择 C#,然后单击代码分析/FxCop 选项卡,然后找到“FxCopCMD.Exe 的路径” " 并按照示例中的建议添加 FXCopCMD.exe 的完整路径

    click on this to see image and process

    【讨论】:

      【解决方案2】:

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

      sonar.cs.fxcop.fxCopCmdPath
      

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

      【讨论】:

      • 感谢您的回答。我在 sonar-project.properties 中指定了“sonar.cs.fxcop.fxCopCmdPath”,然后 FxCop 由正确的路径执行。
      • 请注意,如果您想跳过 FxCop 的执行,您需要从质量配置文件中禁用所有 FxCop 规则。自 SonarQube C# 插件版本 3.0 起,sonar.fxcop.mode 不再受支持。
      • 使用 Maven (sonar:sonar) 从 Jenkins 运行声纳时,当我在 sonar-project.properties 中设置 sonar.cs.fxcop.fxCopCmdPath 属性时,它不服从。但是,当我在 pom.xml 中设置它时,它起作用了。
      猜你喜欢
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 2018-09-04
      • 2022-01-22
      • 1970-01-01
      • 2016-01-27
      相关资源
      最近更新 更多