Using SonarLint with MSBuild

Please provide

  • Operating system: Windows 10
  • SonarLint plugin version: (Visual Studio 2022)
  • Programming language you’re coding in: C# (.Net 6)
  • Is connected mode used: Yes
    • Connected to SonarCloud or SonarQube (and which version): SonarQube on-prem Version

And a thorough description of the problem / question:

I connected my .Net 6 project to our SonarQube project on our SonarQube server (on-prem). When I run code analysis in Visual Studio menu “Analyze - Run Code Analysis” I’m getting all issues reported by SonarQube in the “Error List” window.
My question are:

  1. It is possible to run the SonarQube analysis automatically when starting a Build or Rebuild of my project in Visula Studio (not in commandline)?
  2. It is possible to suppress the compiler warings (CSxxx) on build when using the SonarQube ruleset (describe in question 1). Or isn’t it recommended? Sometimes ít seems that both ruleset will report the same issue.

Best regards

Hi @bmarcouly - welcome to the community, and apologies for the delay in replying.

  1. The Sonar C# rules are implemented as Roslyn analyzers, so Visual Studio controls when they are executed (same as for all Roslyn-based analyzers). As a result, I would expect that setting the Run on build option would do what you want. See the Microsoft docs for more information.

Note: you might also need to set the Error List filter to show Build Only. From memory, the default Build + IntelliSense option isn’t a simple aggregation of all issues found at build time with “live” issues


  1. There are some overlapping rules, so it makes sense to disable one or the other. Controlling which Sonar rules are executed is easy using the Quality Profile. The built-in Microsoft rules can be suppressed in various ways (see the docs). If you want to use a ruleset to disable non-Sonar rules, have a look at this post which describes how to the combine the generated Sonar ruleset with a manual ruleset.