当在QualityProfile中使用FxCop规则时,MSBuild SonarQube提出了“必须设置sonar.cs.fxcop.assembly”的问题。请参阅下面的异常。

它可以与其他StyleCop和C#规则配合使用。
我看过类似的帖子,但找不到解决方案。

我在用 :

C:\Sonar\sonarqube-5.2
C:\Sonar\MSBuild.SonarQube.Runner-1.0.2

已安装以下插件:
插件C#4.3
插件StyleCop 1.1

针对以下示例项目:
C:\Sonar\sonar-examples-master\projects\languages\csharp\ConsoleApplication1

我正在执行以下命令:
cd Sonar\MSBuild.SonarQube.Runner-1.0.2\

MSBuild.SonarQube.Runner.exe begin /k:"MyProjectKey" /n:"MyProjectName" /v:"MyProjectVersion"

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" "C:\Sonar\sonar-examples-master\projects\languages\csharp\ConsoleApplication1\ConsoleApplication1.csproj" /t:Rebuild

MSBuild.SonarQube.Runner.exe end

我试图在.csproj文件中声明程序集的位置,但是没有成功。预期路径是什么样的?
<ItemGroup>
    <SonarQubeSetting Include="sonar.cs.fxcop.assembly">
        <Value>path to dll</Value>
    </SonarQubeSetting>
</ItemGroup>

感谢您的帮助 !

例外情况:
10:33:14.564 INFO  - Sensor org.sonar.plugins.csharp.CSharpFxCopProvider$CSharpF
xCopSensor@1eeeda8
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 12.017s
Final Memory: 14M/113M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:91)
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102
)
        at org.sonar.runner.api.Runner.execute(Runner.java:100)
        at org.sonar.runner.Main.executeTask(Main.java:70)
        at org.sonar.runner.Main.execute(Main.java:59)
        at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.IllegalArgumentException: Cannot find the assembly "C:\Prog
ram Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\Fx
CopSdk.dll" provided by the property "sonar.cs.fxcop.assembly".
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java
:88)
        at org.sonar.plugins.fxcop.FxCopConfiguration.checkAssemblyProperty(FxCo
pConfiguration.java:115)
        at org.sonar.plugins.fxcop.FxCopConfiguration.checkProperties(FxCopConfi
guration.java:97)

最佳答案

错误消息具有误导性:您不应该尝试设置sonar.cs.fxcop.assembly属性。可能发生的情况是,您正在未安装Visual Studio的计算机上运行分析,并且在msbuild本身未触发FxCop时(作为“代码分析” MSBuild任务的一部分)。

对于启用了FxCop规则但未安装FxCop的情况,即将发布的SonarQube Scanner for MSBuild 1.1版已经包含了更好的错误消息。参见https://jira.sonarsource.com/browse/SONARMSBRU-161

关于sonarqube - 必须设置sonar.cs.fxcop.assembly,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33801999/

10-13 02:43