Each IDE extension of SonarLint has its own requirements to work properly with the most recent releases.
In versions prior to v4.34, additional steps were required for some languages. See below for more detail.
See the SonarSource website for information about the currently supported IDEs, and also for details about which languages are supported in which IDEs.
SonarLint is not currently available for
Visual Studio for Mac. Also, the SonarLint extension for
Visual Studio Code does not currently support analysing C# code.
However, it is still possible to use the Sonar C# and VB.NET analyzers in those IDEs with a little manual configuration.
Visual Studio Code and
Visual Studio for Mac all support running Roslyn analyzers that are shipped as NuGet packages. This includes Sonar C# and VB.NET rules.
See below for information on setting up analysis in specific IDEs.
See the OmniSharp blog post from April 2019.
To configure a project to use the Sonar C# analyser, edit the project file to include the following XML:
SonarAnalyzer.VisualBasic instead of
SonarAnalyzer.CSharp to configure the Sonar VB.NET analyzer.
Note that instead of editing every project file, you can create a single Directory.Build.props file at the solution level or repo level that will apply to all projects in the solution/repo.
It is possible to add references to NuGet packages through the UI but that will not add the necessary
Analzyer entries in the project file; you must still add them manually by directly editing the project file. See this StackOverflow post for more information.
|SonarLint for Visual Studio||Minimal required Node.js version|
|v6.9||Node.js v14.17 and higher|
|v6.8||Node.js v12.22 and higher|
|v6.7 and earlier||Node.js v10 and higher, excluding Node.js v11|
SonarLint for Visual will attempt to locate a compatible Node.js version on the machine by searching on the %PATH%. It will also check whether there is a Node.js installation as part of the current Visual Studio installation.
If SonarLint cannot find a compatible Node.js version, it will show a notification in a gold bar like the following:
The Output Window will contain additional information about the Node.js versions that were located:
You can also set the environment variable
SONAR_NODEJS_PATH to specify a custom location. The value should be the full file path to the node executable e.g.
c:\custom\node.exe. The environment variable takes precedence over the automatic detection. You will need to restart Visual Studio after setting or changing the environment variable.
If the machine does not have a compatible version of Node.js, you can manually install one. Node.js versions can be downloaded from the official website nodejs.org. Both the 32-bit and 64-bit versions are supported. The simplest installation method on Windows is to use the appropriate
This page will be updated as the minimum required Node.js version changes.
Analyzing CMake projects
This article is an overview of how to get started with analyzing CMake projects in Visual Studio 2017.3 and later versions, along with information about known issues. This feature is available starting with SonarLint for Visual Studio version 4.38.
If you need more help, please start a post on the SonarLint Community - Visual Studio channel in the Sonar Community forum.
1) Open / create a new CMake project in Visual Studio
2) Add the command
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to the top-level
3) Save the file.
4) Check that VS has generated the compilation database.
Source and header files will now be analyzed on opening/saving. The SonarLint Output Window will contain more information about the progress of the analysis.
If you are creating a new CMake project in VS2019 there appears to be an intermittent issue with VS not recognizing the project as a CMake project until the folder is closed and re-opened. See ticket #2656 for more information.
Follow the same getting started steps as for VS2019 and later above. In addition, to successfully analyze C or C++ files in VS2017 your project will need to use a non-default CMakeSettings.json file. This is because the default CMakeSettings.json file uses the
projectHash macros, which are not supported by SonarLint in VS2017.
1) If you do not already have a CMakeSettings.json file, Visual Studio will create one when you select the Manage Configurations... option and choose a compilation target:
Visual Studio will then create a default CMakeSettings.json file:
2) Edit the CMakeSettings.json file to change the
buildRoot property to one that does not use either
Note: the defaults used by Visual Studio for
installRoot in VS2019 have changed to:
Using those values in VS2017 will allow SonarLint to correctly analyze files in the CMake project.
VS2017 used a different hashing algorithm from VS2019, which is not supported. See issue #2632.
This means that SonarLint will not be able to analyse files if the
buildRoot property uses either of these macros.
SonarLint will not process environment variable overrides in CMakeSettings.json files.
The SonarLint analysis results may be incorrect if the overridden environment variables affect the CMake compilation e.g. changing the paths that are searched for header files.
See the Microsoft documentation for more information about support for CMake presets in Visual Studio.
SonarLint uses the generated compilation database (
compile_commands.json) to fetch the compiler options to use during analysis. The
Ninja generator creates a compilation - the other VS generators do not. Visual Studio introduce support for the
Ninja generator in VS2017 Update 3 (v15.3). Newer versions of VS use the
Ninja generator by default. You can also configure VS to use the
Ninja generator by providing an appropriate
CMakeSettings.json file e.g.
© 2015-2023, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under the GNU Lesser General Public License, Version 3.0. SONARLINT is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners. See SonarSource.com for everything you need to know about the Sonar Solution.