Install Free
Visual Studio | Getting started | Requirements

Requirements

On this page

Each IDE extension of SonarQube for IDE has its own requirements to work properly with the most recent releases.

Overview

SonarQube for Visual Studio is available for Visual Studio version 2022. You can install and run SonarLint in Visual Studio 2019 and 2017, but those versions are no longer supported.

The only thing you need to install is the SonarQube for IDE VSIX available on the Visual Studio Marketplace. Please see the Installation page for complete install instructions.

SonarQube for Visual Studio needs a Java Runtime (JRE) to operate. To specify a JRE, go to Extensions > SonarQube for Visual Studio > Options… > SonarQube for Visual Studio > General > Java Home, add the path to your JRE, and restart your IDE to apply the setting.

  • Your JRE should be version 17+
  • If no path is provided or your path is invalid, SonarQube for Visual Studio will use its own JRE.
You can set your own JRE or use the JRE bundled with SonarLint for Visual Studio.

In versions prior to v4.34, additional steps were required for some languages. See below for more details. 

Supported IDEs

See the SonarSource website for information about the currently supported IDEs, and also for details about which languages are supported in which IDEs.

Unsupported IDEs

SonarQube for Visual Studio is not currently available for Visual Studio for Mac. However, it is still possible to use the Sonar C# and VB.NET analyzers in that IDE with a little manual configuration.

Support for analyzing C# and VB.NET in other IDEs

Visual Studio for Mac supports the running of Roslyn analyzers that are shipped as NuGet packages. This includes Sonar C# and VB.NET rules.

The NuGet package id for the Sonar C# rules is SonarAnalyzer.CSharp. The NuGet package id for the Sonar VB.NET rules is SonarAnalyzer.VisualBasic

See below for information on setting up analysis in specific IDEs.

Visual Studio for Mac

To configure a project to use the Sonar C# analyser, edit the project file to include the following XML:

  <!-- Import and configure the SonarC# analyzer -->
  <PropertyGroup>
    <SonarAnalyzerVersion>8.2.0.14119</SonarAnalyzerVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="SonarAnalyzer.CSharp" Version="$(SonarAnalyzerVersion)" />
    <Analyzer Include="$(NuGetPackageRoot)SonarAnalyzer.CSharp/$(SonarAnalyzerVersion)/analyzers/*.dll" Visible="false" />
  </ItemGroup>

Use 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.

Language-specific requirements

JavaScript and TypeScript analysis

NodeJS prerequisites for JS and TS

Sonar’s JavaScript and TypeScript analyzers require specific Node.js versions to be installed on the machine. If no compatible version is found, the analysis will not be performed. See the table below for the minimal required Node.js version per SonarQube for Visual Studio version:

SonarQube for Visual StudioMinimal required Node.js version
v7.8Node.js v18.17.1 and higher
v7.6Node.js v16 and higher
v6.9Node.js v14.17 and higher
v6.8Node.js v12.22 and higher
v6.7 and earlierNode.js v10 and higher, excluding Node.js v11

Auto-detection of compatible Node.js versions

SonarQube for Visual Studio will attempt to locate a compatible Node.js version on the machine by searching on the %PATH%. If SonarQube for Visual Studio cannot find a compatible Node.js version, it will show a notification in a gold bar like the following:

Your JS/TS analysis will fail if SonarLint cannot find a supported version of Node.js on your computer.

The Output Window will contain additional information about the Node.js versions that were located:

Your Visual Studio Output window will look similar if a compatible Node.js version is not found by SonarLint

Manually specifying a custom location of Node.js installation

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.

Installing Node.js

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 .msi.

Deprecation of older Node.js versions

From time to time the Sonar JavaScript/TypeScript analyzer will increase the minimum required Node.js version as older versions go out of support. The dropping of support will be announced in advance in the Community Forum (e.g. this post regarding the deprecation of Node.js v12 and dropping of support for Node.js vs10).

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 SonarQube for Visual Studio version 4.38.

If you need more help, please start a post on the SonarQube for IDE Community - Visual Studio channel in the Sonar Community forum.

Getting started - VS2019 and later

1) Open / create a new CMake project in Visual Studio

2) Add the command set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to the top-level CMakeLists.txt file:

Add a command to your CMakeLists.txt file to generate the compilation database.

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 SonarQube for Visual Studio Output Window will contain more information about the progress of the analysis.

Getting started - VS2017.3

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 workspaceHash or projectHash macros, which are not supported by SonarQube for IDE 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 create a CMakeSettings.json file if you do not already have one.

Visual Studio will then create a default CMakeSettings.json file:

Your new CMakeSetting.json file looks like this.

2) Edit the CMakeSettings.json file to change the buildRoot property to one that does not use either workspaceHash or projectHash.

Note: the defaults used by Visual Studio for buildRoot and installRoot in VS2019 have changed to:

      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",

Using those values in VS2017 will allow SonarQube for Visual Studio to correctly analyze files in the CMake project.

CMake - known limitations

VS2017: workspaceHash and projectHash macros are not supported in VS2017

VS2017 used a different hashing algorithm from VS2019, which is not supported. See issue #2632.

This means that SonarQube for Visual Studio will not be able to analyse files if the buildRoot property uses either of these macros.

Environment variable overrides in CMakeSettings.json are not supported

SonarQube for Visual Studio will not process environment variable overrides in CMakeSettings.json files.

The SonarQube for Visual Studio 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.

CMake presets are not currently supported by SonarQube for Visual Studio

See the Microsoft documentation for more information about support for CMake presets in Visual Studio.

Only the Ninja generator is supported

SonarQube for Visual Studio 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.

{
  "configurations": [
    {
      ... 
      "name": "x64-Release",
      "generator": "Ninja",
      ...
      "buildRoot": "${projectDir}\\out\\build\\${name}\\",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      ...
    }
  ]
}

Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License