Search code examples
c#sonarqubefxcop

sonar msbuild run from Jenkins: sonar.cs.fxcop.assembly must be set


I have gone through the previous questions on the subject but whatever answer was given does not seem to work for me

My setup is - Microsoft Visual Studio Community 2017 installed - SonarQube server Version 5.6.2 - SonarQube MSbuild Scanner: 4.2.0.1214

the log I am getting when running

Sensor org.sonar.plugins.csharp.CSharpSensor (done) | time=2847ms INFO: Sensor org.sonar.plugins.csharp.CSharpFxCopProvider$CSharpFxCopSensor INFO: ------------------------------------------------------------------------ INFO: EXECUTION FAILURE INFO: ------------------------------------------------------------------------ INFO: Total time: 17.829s INFO: Final Memory: 21M/421M INFO: ------------------------------------------------------------------------ ERROR: Error during SonarQube Scanner execution ERROR: 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".

What I do not know is - how do I know that fxcop is enabled in the build process, if that makes any sense and if anything needs doing ? - why am I getting this error message when all the post I have seen tend to say "that should not happen if using sonar msbuild and visual studio"

thank you


Solution

  • The history of how FxCop was supported is a bit complicated, and depends on which version of the SonarC# plugin you are using and which version of the Scanner for MSBuild you are running. Native support for FxCop in the SonarC# plugin/Scanner for MSBuild has been deprecated for some time and was finally removed from the Scanner for MSBuild in version 4.0.

    How do I know that fxcop is enabled in the build process?

    Check which plugins you have installed on the SonarQube server. My guess is that you either have an old version of the SonarC# plugin (pre-v5.4) installed or have the community FxCop plugin installed. Also, if you look at the Quality Profile for your project you will see that some of the rules in the Repository FxCop / Code Analysis C# are enabled.

    It's up to you to decide whether you want to run the FxCop rules as part of your build or not. The SonarC# plugin now natively implements all of the most useful FxCop rules so the approach recommended by SonarSource is just to use the SonarC# plugin for new projects.

    If you are using v4 or later of the Scanner for MSBuild and do want to upload FxCop issues, check you have the latest version of the FxCop Community plugin installed and follow the instructions in the Use with SonarQube Scanner for MSBuild v4.0 section of the Readme for the plugin.

    If you don't want to upload FxCop issues for this particular project, you can deactivate all of the FxCop rules in the Quality Profile. If you are not interested in seeing FxCop issues for any project, you can uninstall the FxCop plugin if it is installed, and upgrade to a newer version of the SonarC# plugin (note: SonarQube 5.6.2 is quite an old version, so you won't be able to install the newest version of the SonarC# plugin unless you upgrade the SonarQube server first).