Using SonarLint with MSBuild

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

image

  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.