Search code examples
sonarqubefxcop

sonar.cs.fxcop.assembly must be set


MSBuild SonarQube is raising the issue 'sonar.cs.fxcop.assembly must be set' when using FxCop rules in the QualityProfile. See exception below.

It is working fine with other StyleCop and C# rules. I had a look to similar posts but couldn't find a solution.

I am using :

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

The following plugins are installed: Plugin C# 4.3 Plugin StyleCop 1.1

Targeting the following sample project:

C:\Sonar\sonar-examples-master\projects\languages\csharp\ConsoleApplication1

I am executing the following commands :

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

I have tried to declare the assembly location in the .csproj file but without success. What does the expected path looks like ?

<ItemGroup>
    <SonarQubeSetting Include="sonar.cs.fxcop.assembly">
        <Value>path to dll</Value>
    </SonarQubeSetting>
</ItemGroup>

Thank you for your help !

Exception :

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)

Solution

  • The error message is misleading: You shouldn't try to set the sonar.cs.fxcop.assembly property. What is probably happening is that you are running the analysis from a machine on which Visual Studio is not installed, and FxCop is not being triggered during msbuild itself (as part of the "Code Analysis" MSBuild task).

    The upcoming SonarQube Scanner for MSBuild version 1.1 already includes a better error message for the case when FxCop rules are enabled, but FxCop isn't installed. See https://jira.sonarsource.com/browse/SONARMSBRU-161