3

I have a question regarding FXCop analysis using SonarQube with the MSBuild-Runner. I have realized that the MSBuild-Runner loads a rules file from the server which matches the quality profile in Sonar and uses that file for the FXCop run.

In our project we have a solution with several projects. For each project a rules file is configured depending on its type e.g. product or test code. We also use custom rules in own FXCop assemblies.

How can I configure MSBuild-Runner so that he uses the rules file which is configured in the project file? How can I add our custom rules into Sonar? Can I import our rules files somehow?

Thanks for your help!

Pascal Berger
  • 4,262
  • 2
  • 30
  • 54
chuchu42
  • 107
  • 1
  • 10

1 Answers1

3

You must use a single quality profile to analyze all projects within your solution. Indeed, only a single quality profile is used during a SonarQube analysis. In theory, you could create two quality profiles in SonarQube, and run two SonarQube analysis (one for example on all product code, and another one on all test code), but this requires some manual setup on your side.

Regarding custom rules, they are supported: You need to create them in SonarQube web interface from the "Template for custom FxCop rules" rule template, and then enable the newly created custom rules in your quality profile.

Dinesh Bolkensteyn
  • 2,971
  • 1
  • 17
  • 20
  • Mh, I think that's a drawback of the msbuid-runer. He creates its own rule-set from the quality profile in SonarQube and ignores the one from the project file. It would be nice if there would be an option to don't do that. In that case SonarQube would get those findings but report them only if they are in the quality profile. Adding a lot of custom rules using the web interface is tedious. But I figured out how to work with the REST API. It should be possible to write a tool which imports a fxcop rule set to SonarQube. – chuchu42 Oct 21 '15 at 19:12
  • indeed it's tedious, and there is a ticket to add an automatic importer: https://jira.sonarsource.com/browse/SONARFXCOP-39 – Dinesh Bolkensteyn Oct 23 '15 at 08:40
  • Is someone planning to start working on that? Maybe I can help. – chuchu42 Oct 29 '15 at 07:02
  • feel free to submit a pull request on GitHub to add this feature - it's going to have to be written in Java though, and you'll have to extend/implement the `ProfileImporter` SonarQube extension point I believe, see https://github.com/SonarCommunity/sonar-fxcop-library – Dinesh Bolkensteyn Oct 29 '15 at 07:54
  • and `ProfileImporter` is here: https://github.com/SonarSource/sonarqube/blob/master/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java – Dinesh Bolkensteyn Oct 29 '15 at 07:54