SonarLint in Visual Studio for C# Code - Apparently it does not run the ruleset on files

visualstudio
sonarlint

(Jessica Wang) #1

I am just starting to use SonarLint in Visual Studio 2017 for my existing C# code it seems not running the ruleset on files unless they are all opened in the IDE - which I don’t like it because the solution project may have many many files. Could you confirm this behavior is right or I missed something. If that’s the behavior now I also want to know if there are plans to change it to run against the entire solution whether the file is opened or not?


(Valeri Hristov) #2

Thanks for your interest in SonarLint for Visual Studio! You are right, the default behavior of SonarLint is to analyze only the open files. This is to prevent the majority of the project issues from appearing in your Error List window and letting you focus on what’s important (the files you currently work on).

To change this behavior you need to enable the Full Solution Analysis setting in Visual Studio:

Since the analysis is asynchronous, it might take some time for all issues to appear in a large project.

Another option could be to add the SonarAnalyzer nugets to your project. This way the analysis will run on each build and you will have all issues listed in the Output and Error windows. Be aware, though, that this will significantly slow down the build times.


(Jessica Wang) #3

Thanks Valeri for the info! The solution you provided did work - however, it was extremely resource intensive and slow. It has also noticed that there are additional errors in VS 2017 that are attributed to SonarQube server then it’s seen when looking at the issues up on the Sonarqube website.


(Valeri Hristov) #4

Yes, it is true that the analysis is very resource heavy. The C# compiler is executing the analyzers in parallel and that usually renders the machine nearly unusable while the compilation is in progress. That’s why the default setting in Visual Studio is to analyze only the opened files and not the whole solution (it’s a VS setting, it does not come from SonarLint).