Ruleset names are unknown. Is this the expected experience?

SonarQube all connected and projects bound to quality profiles, have “updated” rulesets based on prompt in errors & warnings pane. But ruleset rule names all show as “unknown”.

edit: I’ve fixed the “one or more included rule sets could not be loaded” issue, was an incorrect relative path in an include which is no longer the case.

As I’m new to SonarQube, I don’t know if this is right or wrong? But I would hazard a guess that this ruleset view is very unhelpful.

I’ve downloaded the example ruleset xml from the Sonarcloud and none of them have names.

Microsoft Visual Studio Enterprise 2017 
Version 15.9.10
VisualStudio.15.Release/15.9.10+28307.557
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Enterprise

ASP.NET and Web Tools 2017   15.9.04012.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.60913.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.9.03024.0
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   15.9.02046.0
Azure Functions and Web Jobs Tools

C# Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GitHub.VisualStudio   2.8.1.7307
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

LineEndingsUnifierPackage Extension   1.0
LineEndingsUnifierPackage Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.0.0

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NPM Task Runner   1.4.90
Adds support for npm scripts defined in package.json directly in Visual Studio's Task Runner Explorer. Includes full support for Yarn

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PowerShell Pro Tools for Visual Studio   1.0
A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio.

Productivity Power Tools 2017/2019   16.0
Installs the individual extensions of Productivity Power Tools 2017/2019

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SonarLint for Visual Studio   4.9.0.4316
SonarLint is an extension to your favorite IDE that provides on-the-fly feedback to developers on new bugs and quality issues injected into their code.

SQL Server Data Tools   15.1.61903.01040
Microsoft SQL Server Data Tools

TypeScript Tools   15.9.20918.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5   15.8.0.0.  Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

If you are using connected mode then the standard VS ruleset view isn’t particularly useful as far as the SonarAnalyzer rules go. The expectation is that you’d configure the SonarC#/VB rules in the Quality Profile in SonarQube/Cloud, and SonarLint will then generate a ruleset from the Quality Profile so VS knows which SonarC#/VB rules to run.

What do you mean by “I’ve downloaded the example ruleset xml from the Sonarcloud” - you’ve bound the solution and opened the generated ruleset?

The generated ruleset should look something like this:

  <Rules AnalyzerId="SonarAnalyzer.CSharp" RuleNamespace="SonarAnalyzer.CSharp">
    <Rule Id="S100" Action="None" />
    <Rule Id="S1006" Action="Warning" />
    <Rule Id="S101" Action="Warning" />

It’s a standard VS ruleset file, and it isn’t expected to contain rule names or descriptions.

However, I would expect VS to correctly show the names of the rules in the IDE. I haven’t seen a case with the rule names displayed as “unknown” before.

1 Like

Apologies for the delay in my reply.

I am pleased to see that it works for you! My question is answered. Indeed, I would like the ruleset file editor to appear as it does for you. I am not experiencing the expected experience.

A long, long time ago when I was writing FxCop static code analysis rules, I can remember having to put the analyzer library into a special Visual Studio folder for them to be picked up in the ruleset editor. Regrettably I can’t remember anything in more detail, as it was a long time ago.

I guess I should be copying a SonarAnalyzer library into a Visual Studio folder somewhere? Or installing something? I haven’t installed anything special on my workstation to use the SonarSource suite, just Nuget packages.

Have you installed the SonarLint extension for Visual Studio? Or have you just added an XML ruleset file to your project? If you’ve just added a ruleset file then that would explain why Visual Studio can’t provide any more detail about the rules in the UI.

Roslyn analyzers work differently from FxCop analyzers. They can be packaged as either NuGet packages or in VSIXes (or both). The Microsoft docs explain the differences.

Our recommendation would be to install the SonarLint vsix. This will make the SonarC# and SonarVB.NET rules analyser rules available for every solution you open without you having to make any changes to individual MSBuild projects (note however that the analysis rules will only be run in the IDE; they won’t be run when you build from the command line).

That is a useful link, and useful advice. I will attempt to install the SonarLint extension, if I hadn’t already done so. I do note in my original article, that I appear to have this installed in my list of Visual Studio extensions:

SonarLint for Visual Studio   4.9.0.4316
SonarLint is an extension to your favorite IDE that provides on-the-fly feedback to developers on new bugs and quality issues injected into their code.

Alas the one on the market place via your link says 4.10.0.9867. I am away for 2 weeks, I will attempt to upgrade it and report back my experience.

Thanks for your help.

1 Like