1
votes

The new version (2.0) of the Resharper plugin for Sonar was extended with the feature of importing an existing Resharper DotSettings file. However, If I set a settings file when I create my quality profile, its settings are not being picked up.

I tried to use the following simple DotSettings file, the only setting in it is disabling the _ prefix of private field names:

<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
</wpf:ResourceDictionary>

But even after creating my quality profile with specifying the above DotSettings file, and using this quality profile to analyze a project, I still get the Name 'xyz' does not match rule 'Instance fields (private)'. Suggested name is '_xyz'. errors.

Also, if I try to download the settings file of my quality profile from the Permalinks tab, it contains a bunch of rules, but it doesn't contain the rule I had in the DotSettings file I imported.

What is the reason for this? Am I doing something wrong?

UPDATE: I looked around a little bit more, but I just got more confused. I've seen that a new version of a runner called "MSBuild SonarQube Runner", but there is also a runner simply called "SonarQube Runner" which we have been using until now.
So the normal SonarQube Runner hasn't been deprecated, but for .NET projects using Resharper, we should start using the MSBuild SonarQube Runner, and that with that we will be able to specify a custom DotSettings file to use when running inspectcode.exe? Or we should manually run inspectcode from the command line?

1
I just noticed I see the ReSharper plugin is running in deprecated mode warning message in the logs, maybe it's related?Mark Vincze

1 Answers

3
votes

All .NET projects should now be analyzed using the MSBuild SonarQube Runner, which was developed jointly with Microsoft and which offers the best experience for .NET users.

As a consequence, the use of the sonar-runner for .NET projects is now deprecated. For COBOL, PL/SQL, and other many other languages (excluding C# and VB.NET), the sonar-runner is still the recommended way to analyze projects.

Since the release of the SonarQube ReSharper version 2.0 plugin, the re-use reports mode is now the preferred one. This means that we expect you to launch inspectcode.exe and generate a report. Then, set the sonar.resharper.cs.reportPath property to the path of that report, as well as sonar.resharper.solutionFile to the path of your solution file, when launching the MSBuild SonarQube Runner.

Here are the steps to analyze a project with R#'s command line inspectcode.exe tool and the MSBuild SonarQube Runner:

  1. inspectcode.exe /report=[report path] [solution path]
  2. MSBuild.SonarQube.Runner.exe begin /k:[SQ Project Key] /n:[SQ Project Name /v:[SQ Project Version] /d:sonar.resharper.cs.reportPath=[report path] /d:sonar.resharper.solutionFile=[solution path]
  3. msbuild
  4. MSBuild.SonarQube.Runner.exe end

It is your responsibility to launch inspectcode.exe with settings that are consistent with the ones set in SonarQube. To make this easy, the SonarQube R# 2.0 plugin allows you to export the rules into a .DotSettings file and provides a permalink to it. Have a look at the plugin's documentation for more info: http://redirect.sonarsource.com/plugins/resharper.html

Now, let's come back to your original problem, which is that the R# .DotSettings import in SonarQube is not working, there are several issues:

  1. When you import a .DotSettings file into SonarQube, it goes into a new Quality Profile. You need to make sure that this new quality profile will be used for the analysis of your project, either by setting it as the default one, or by explicitly setting the quality profile in your project's Settings page. You also should export that very same new quality profile to check that the import worked properly.
  2. The format of the .DotSettings file you are passing is not understood by the importer, which expects key tags to start with /Default/CodeInspection/Highlighting/InspectionSeverities/= - and all R# rules will remain disabled.
  3. R# rule customization in SonarQube will not work - the only information saved is whether the rule is enabled or not. Any different customization will not be present in the export. With the new re-use reports mode, this will no longer be blocker, as you can provide inspectcode.exe with a fully customized .DotSettings file (instead of being limited to a SonarQube's generated one).
  4. The one rule you are testing does not seem to be present the rule set of the SonarQube R# Plugin 2.0 (see https://raw.githubusercontent.com/SonarCommunity/sonar-resharper/master/src/main/resources/org/sonar/plugins/resharper/rules.xml for the full list) and http://jira.sonarsource.com/browse/SONARRSHPR-17