3
votes

I am trying to migrate from the old Sonar runner to the new MsBuild Sonar runner in a .NET project.

The last problem I have is doing the FxCop analysis. If the quality profile in Sonar contains any FxCop rules, I get the following build error:

ERROR: Caused by: 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".

I googled a lot and found some rather old topics with the same problem, but none of the solutions worked.
I tried to add the sonar.visualstudio.enable="true" parameter, but then I get the following error:

ERROR: Caused by: Do not use the Visual Studio bootstrapper and set the "sonar.modules" property at the same time.

Also tried to add /d:sonar.visualstudio.skipIfNotBuilt="true", but it didn't help.

What am I doing wrong? How to parameterize the new MsBuild sonar runner to make the FxCop analysis work?

These are the commands I'm executing (I modified the file names an paths):
1. Sonar runner begin

MSBuild.SonarQube.Runner.exe begin /key:"MyProject" /name:"MyProject"
/version:"1" /d:sonar.host.url="http://mysonarhost/" /d:sonar.jdbc.dialect="mssql"
/d:sonar.jdbc.url="jdbc:jtds:sqlserver://mysonardb" /d:sonar.jdbc.username="sonar-user"
/d:sonar.jdbc.password="sonar-password" /d:sonar.resharper.cs.reportPath="../../../../resharperresults.xml"
/d:sonar.resharper.solutionFile="MySolution.sln"
/d:sonar.visualstudio.testProjectPattern=".*\.(UnitTests|IntegrationTests)"
/d:sonar.exclusions="obj/**" /d:sonar.dotnet.excludeGeneratedCode="true"
/d:sonar.cs.fxcop.fxCopCmdPath="..\Tools\FxCop.v12.0.21005.1\FxCopCmd.exe"
/d:sonar.visualstudio.solution="MySolution.sln" /d:sonar.dotnet.buildConfigurations="Release"
/d:sonar.language="cs" /d:sonar.sourceEncoding="UTF-8"
/d:sonar.cs.opencover.reportsPaths="..\CodeCoverage\MSTest.Coverage.MySolution.UnitTests.xml"
  1. MsBuild:

MSBuild.exe targets.msbuild ...

  1. ReSharper analysis:

inspectcode.exe /o=resharperresults.xml MySolution.sln

  1. Runner end:

MSBuild.SonarQube.Runner.exe end

1
Or with the new runner, the FxCop report has to be manually generated, similarly to the ReSharper report?Mark Vincze
No, FxCop is supposed to be enforced during MSBuild - that is, unless you have heavily customized your .csproj and MSBuild files - is that the case?Dinesh Bolkensteyn
You can remove the unused properties: sonar.cs.fxcop.fxCopCmdPath, sonar.visualstudio.solution, sonar.visualstudio.testProjectPatternDinesh Bolkensteyn
Perhaps try to do a full MSBuild rebuild, and send the logs of thatDinesh Bolkensteyn

1 Answers

0
votes

I recommend to upgrade to the newly released MSBuild SonarQube Runner version 1.0.1, which will force the Visual Studio Bootstrapper plugin to be disabled. Once you have migrated all your projects to use the MSBuild SonarQube Runner, you should uninstall the Visual Studio Bootstrapper plugin from your SonarQube server.

Then, all the SonarQube server and JDBC properties such as sonar.host.url or sonar.jdbc.url are better passed through the SonarQube.Analysis.xml file than through the command line.

The following properties are useless: sonar.visualstudio.testProjectPattern, sonar.dotnet.excludeGeneratedCode, sonar.cs.fxcop.fxCopCmdPath, sonar.visualstudio.solution, sonar.dotnet.buildConfigurations

sonar.language can be removed as SonarQube supports multi-language projects since SonarQube version 4.2.

For OpenCover, have a look at: http://docs.sonarqube.org/display/PLUG/C%23+Code+Coverage+Results+Import#C#CodeCoverageResultsImport-OpenCover

For ReSharper, at: http://docs.sonarqube.org/display/PLUG/ReSharper+Plugin

FxCop is natively supported, and its execution will happen during msbuild when FxCop rules are enabled in your quality profile.