This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

SonarScanner for .NET

The SonarScanner for .NET is the recommended way to launch an analysis for projects built using MSBuild or dotnet.

SonarScanner for .NET — 10.4.1.124928 | Issue Tracker

10.4.1.124928 2025-09-23 Fix a bug that erroneously warns that Community Build is not supported. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.4.0.124828 2025-09-22 New communication system with SonarQube. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.3.0.120579 2025-07-16 Support xUnit v3, fix RunDeploymentRoot in trx files, remove sonar.scanner.scanAll analysis warning. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.2.0.117568 2025-06-03 Fix a vulnerability from embedded scanner-cli. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.1.2.114627 2025-04-16 Add 'sonar' default truststore passord fallback. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.1.1.111189 2025-03-25 Maintenance and dependencies updates. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.1.0 2025-03-19 Maintenance and dependencies updates. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


10.0.0 2025-03-13 Fix a vulnerability. Mandate that the truststore password is passed in the end step if used in the begin step. Added support for 7 new languages. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.2.1 2025-02-25 DEPRECATED. Use system trusted certificate or JVM certificate store. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.2.0 2025-02-19 DEPRECATED. Support for local trust store for private and self-signed certificates. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.1.0 2025-02-06 Read new properties for downloading plugins Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.0.2 2024-11-12 sonar.projectBaseDir passed through extraProperties is respected with Azure DevOps extensions. Do not fail during file indexing when a directory cannot be accessed. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.0.1 2024-10-25 Fix projectBaseDir path detection on Azure DevOps Linux agents. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


9.0.0 2024-09-27 Ignore sonar.sources and sonar.tests properties. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


8.0.3 2024-09-13 Exclude XML files from the new automatic analysis. Do not crash on mlaformed paths. Make sure server-side exclusions are not overridden. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


8.0.2 2024-09-02 Re-enabled sonar.exclusions support. Automatically exclude files passed-in as coverage. Skip transient projects that do not exist after the build. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


8.0.1 2024-08-21 Bug fix release which addresses two issues, improvements on messages emmitted during the analysis. Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


8.0 2024-08-12 The scanner is now supporting multi-language analysis. Files for other languages are automatically picked up (SQL, YAML, XML, JSON, CSS, HTML, JS, TS) Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


7.1.1 2024-07-24 Fixed a small issue when not specifying sonar.host.url (defaults to https://sonarcloud.io) Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


7.1 2024-07-19 Fixed a small issue when not specifying sonar.host.url (defaults to https://sonarcloud.io) Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


7.0 2024-07-18 This version does not require a JRE to be present on the machine anymore Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


6.2 2024-02-16 Fixes the failing analysis on macOS with .NET 8.0. New optional sonar.http.timeout command line parameter Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


6.1 2024-01-29 Drop support for MSBuild 14, deprecate MSBuild 15 Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


6.0 2023-12-04 Packaging change, drop support for .Net Framework 4.6, Net 2.1, and .Net 3.0. Drop Java 11 support. Drop support of SonarQube versions prior to 8.9 Download scanner for: .NET Global Tool .NET Core 3.1+ .NET Framework 4.6.2+ Release notes


5.15.1 2024-03-26 Fix analysis on MacOSX with .NET 8 when begin runtime doesn't match with build runtime Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.15 2023-11-20 Add an option to specify the scanner's temporary working directory Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.14 2023-10-02 Support upcoming SonarQube 10.4 API changes Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.13.1 2023-08-14 SonarScanner CLI update Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.13 2023-04-05 Support for sonar.token parameter and improved error messages Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.12 2023-03-17 Fast PR Analysis Support For Azure Devops Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.11 2023-01-27 Fast PR Analysis Compatibility Fix Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.10 2023-01-13 Improved FIPS Compliance Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.9.2 2022-12-14 Bug Fix Release related to PR analysis Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.9.1 2022-12-06 Bug Fix Release Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.9.0 2022-12-01 .NET 7 bug fixes and preparation for fast PR analysis Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.8.0 2022-08-24 Analysis of Azure Functions on Github Actions no longer hard fails with default behavior. See release notes for details. Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.7.2 2022-07-12 Log warning instead of error when not parsing environment variables to avoid hard failure when Newtonsoft does not get resolved Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.7.1 2022-06-21 Bug Fix Release Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.7.0 2022-06-20 Bug Fix Release Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.6.0 2022-05-30 Send warnings to users of versions where support will change Download scanner for: .NET 5+ .NET Global Tool .NET Core 3.1 .NET Core 2.1 .NET Framework 4.6 Release notes


5.5.3 2022-02-14 Support for .NET 6 Web Projects, TLS Version selection logic removed - now responsibility of OS, Fix "MSB3677 Unable to move file" regression Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.5.2 2022-02-10 Support for .NET 6 Web Projects, TLS Version selection logic removed, now responsibility of OS Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.5.1 2022-02-08 Support for .NET 6 Web Projects, support TLS 1.3 where supported by environment Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.5.0 2022-02-07 Support for .NET 6 Web Projects, support TLS 1.3 Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.4.1 2021-12-23 Updated Newtonsoft.Json to latest Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.4 2021-11-26 Updated .NET 5 Version to be forward compatible and support .NET 6 environments Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.3.2 2021-10-28 Added parameters sonar.clientcert.path and sonar.clientcert.password for securing connections to SonarQube Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.3.1 2021-09-01 Update scanner-cli, Compile with .NET Core 2.1 and 3.1, Improve uninstall of targets if multiple builds in the same pipeline Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.2.2 2021-06-24 Fix test assembly detection + mTLS certificate with password Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.2.1 2021-04-30 Update embedded SonarScanner CLI Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.2 2021-04-09 Support for test code analysis Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.1 2021-03-09 Support for .NET 5, support for solo .NET Core project (without .sln) Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.0.4 2020-11-11 Support for .NET 5, support for solo .NET Core project (without .sln) Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.0.3 2020-11-10 Support for .NET 5, support for solo .NET Core project (without .sln) Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


5.0 2020-11-05 Support for .NET 5, support for solo .NET Core project (without .sln) Download scanner for: .NET 5+ .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


4.10 2020-06-29 Support FIPS compliant cryptographic algorithm Download scanner for: .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


4.9 2020-05-05 Improve detection of duplicated coverage reports, fix categorization of fakes projects Download scanner for: .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


4.8 2019-11-06 Enable scanner execution when only .NET Core 3 is installed Download scanner for: .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


4.7.1 2019-09-10 Update SonarScanner to version 4.1 Download scanner for: .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes


4.7 2019-09-03 Support dash and forward-slash in dotnet command line arguments, analyze XAML files, add analyzed targets in logs Download scanner for: .NET Global Tool .NET Core 2.1 .NET Framework 4.6 Release notes

In version 5.0, we changed the name of the SonarScanner for MSBuild to SonarScanner for .NET.

The documentation is updated with the new name and we will call the scanner SonarScanner for .NET moving forward.

The SonarScanner for .NET is the recommended way to launch an analysis for projects built using MSBuild or dotnet. It is the result of a collaboration between SonarSource and Microsoft.

SonarScanner for .NET is distributed as a standalone command line executable, as an extension for SonarQube extension for Azure DevOps, and as a plugin for Jenkins extension for SonarQube.

It supports .NET Core on every platform (Windows, macOS, Linux).

Prerequisites

  • At least the minimal version of Java supported by your SonarQube server

    • Java 17 is required to run this version of the scanner. If you are running a previous version of Java, you will need a previous version of the scanner.

  • The SDK corresponding to your build system:

  • The minimum supported version for SonarQube is now 8.9.

    • The scanner will fail to start if an older version of SonarQube is detected.

The flavor used to compile the Scanner for .NET (either .NET Framework, .NET Core or .NET) is independent of the .NET version the project you want to analyze has been built with. Concretely, you can analyze .NET Core code with the .NET Framework version of the Scanner. It’s only relevant depending on your OS, and on the versions of .NET SDKs that are installed on your build machine.

Installation

Standalone executable

  • Expand the downloaded file into the directory of your choice. We’ll refer to it as <INSTALL_DIRECTORY> in the next steps.

    • On Windows, you might need to unblock the ZIP file first (right-click file > Properties > Unblock).

    • On Linux/OSX you may need to set execute permissions on the files in <INSTALL_DIRECTORY>/sonar-scanner-(version)/bin.

  • Uncomment, and update the global settings to point to your SonarQube server by editing <INSTALL_DIRECTORY>/SonarQube.Analysis.xml. Values set in this file will be applied to all analyses of all projects unless overwritten locally. Consider setting file system permissions to restrict access to this file.

<SonarQubeAnalysisProperties  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
  <Property Name="sonar.host.url">http://localhost:9000</Property>
  <Property Name="sonar.login">[my-user-token]</Property>
</SonarQubeAnalysisProperties>
  • Add <INSTALL_DIRECTORY> to your PATH environment variable.

.NET Core global tool

dotnet tool install --global dotnet-sonarscanner --version x.x.x

The --version argument is optional. If it is omitted the latest version will be installed. The full list of releases is available on the NuGet page.

.NET Core Global Tool is available from .NET Core 3.1+.

On Linux/OSX, if your SonarQube server is secured

  1. Copy the server’s CA certs to /usr/local/share/ca-certificates

  2. Run sudo update-ca-certificates

Use

You can invoke the Scanner using arguments with both dash (-) or forward-slash (/) separators. Either of the following will work:

  • SonarScanner.MSBuild.exe begin /k:"project-key"

  • SonarScanner.MSBuild.exe begin -k:"project-key"

There are two versions of the SonarScanner for .NET. In the following commands, you need to pass an Generating and using tokens using the sonar.login property. Any project file accepted by MSBuild.exe or dotnet can be used, for example .sln, .proj, .csproj, or .vbproj.

"Classic" .NET framework invocation

The first version is based on the "classic" .NET Framework. To use it, execute the following commands from the root folder of your project:

SonarScanner.MSBuild.exe begin /k:"project-key" /d:sonar.login="myAuthenticationToken"
MSBuild.exe <path to project file or .sln file> /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="myAuthenticationToken"

Note: On macOS or Linux, you can also use mono <path to SonarScanner.MSBuild.exe>.

.NET Core and .NET Core global tool invocation

The second version is based on .NET Core which has a very similar usage:

dotnet <path to SonarScanner.MSBuild.dll> begin /k:"project-key" /d:sonar.login="<token>"
dotnet build <path to project file or .sln file>
dotnet <path to SonarScanner.MSBuild.dll> end /d:sonar.login="<token>" 

The .NET Core version can also be used as a .NET Core Global Tool. After installing the Scanner as a global tool as described above it can be invoked as follows:

dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"project-key" /d:sonar.login="<token>"
dotnet build <path to project file or .sln file>
dotnet sonarscanner end /d:sonar.login="<token>"

Scanner Flavor

Invocation

.NET Core Global Tool

dotnet sonarscanner begin etc.

.NET Core 3.1+

dotnet <path to SonarScanner.MSBuild.dll> etc.

.NET Framework 4.6.2+

SonarScanner.MSBuild.exe begin etc.

Notes:

  • The .NET Core version of the scanner does not support TFS XAML builds and automatic finding/conversion of Code Coverage files. Apart from that, all versions of the Scanner have the same capabilities and command line arguments.

Analysis steps

Begin

The begin step is executed when you add the begin command line argument. It hooks into the build pipeline, downloads SonarQube quality profiles and settings, and prepares your project for analysis.

Command Line Parameters:

Parameter

Description

/k:<project-key>

[required] Specifies the key of the analyzed project in SonarQube

/n:<project name>

[optional] Specifies the name of the analyzed project in SonarQube. Adding this argument will overwrite the project name in SonarQube if it already exists.

/v:<version>

[recommended] Specifies the version of your project.

/d:sonar.login=<token>

[recommended] Specifies the Generating and using tokens used to authenticate with to SonarQube. If this argument is added to the begin step, it must also be added to the end step.

/d:sonar.clientcert.path=<ClientCertificatePath>

[optional] Specifies the path to a client certificate used to access SonarQube. The certificate must be password protected.

/d:sonar.clientcert.password=<ClientCertificatePassword>

[optional] Specifies the password for the client certificate used to access SonarQube. Required if a client certificate is used.

/d:sonar.verbose=true

[optional] Sets the logging verbosity to detailed. Add this argument before sending logs for troubleshooting.

/d:sonar.dotnet.excludeTestProjects=true

[optional] Excludes Test Projects from analysis. Add this argument to improve build performance when issues should not be detected in Test Projects.

/d:<analysis-parameter>=<value>

[optional] Specifies an additional SonarQube Analysis parameters, you can add this argument multiple times.

/s:<custom.analysis.xml>

[optional] Overrides the $install_directory/SonarQube.Analysis.xml. You need to give the absolute path to the file.

For detailed information about all available parameters, see Analysis parameters.

Build

Between the begin and end steps, you need to build your project, execute tests and generate code coverage data. This part is specific to your needs and it is not detailed here. See .NET test coverage for details.

End

The end step is executed when you add the "end" command line argument. It cleans the MSBuild/dotnet build hooks, collects the analysis data generated by the build, the test results, the code coverage and then uploads everything to SonarQube

There are only two additional arguments that are allowed for the end step:

Parameter

Description

/d:sonar.login=<token>

This argument is required if it was added to the begin step.

/d:sonar.clientcert.password=<ClientCertificatePassword>

This argument is required if it was added to the begin step. Specifies the password for the client certificate used to access SonarQube.

Known limitations

  • MSBuild versions older than 15 are not supported.

  • Web Application projects are supported. Legacy Web Site projects are not.

  • Projects targeting multiple frameworks and using preprocessor directives could have slightly inaccurate metrics (lines of code, complexity, etc.) because the metrics are calculated only from the first of the built targets.

Code coverage

See .NET test coverage for details.

Excluding projects from analysis

Some project types, such as Microsoft Fakes, are automatically excluded from analysis. To manually exclude a different type of project from the analysis, place the following in its .xxproj file.

<!-- in .csproj –->
<PropertyGroup>
  <!-- Exclude the project from analysis -->
  <SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>

Advanced topics

Analyzing MSBuild 12, 14, and 15 projects with MSBuild 16

The Sonar Scanner for .NET requires your project to be built with MSBuild 14.0. We recommend installing Visual Studio 2017 or later on the analysis machine in order to benefit from the integration and features provided with the Visual Studio ecosystem (VSTest, MSTest unit tests, etc.).

Projects targeting older versions of the .NET Framework can be built using MSBuild 16 by setting the "TargetFrameworkVersion" MSBuild property as documented by Microsoft:

For example, if you want to build a .NET 3.5 project, but you are using a newer MSBuild version:

MSBuild.exe /t:Rebuild /p:TargetFramework=net35

If you do not want to switch your production build to MSBuild 16, you can set up a separate build dedicated to the SonarQube analysis.

Detection of test projects

You can read a full description of that subject on our wiki here.

Per-project analysis parameters Some analysis parameters can be set for a single MSBuild project by adding them to its .csproj file.

<!-- in .csproj -->
<ItemGroup>
  <SonarQubeSetting Include="sonar.stylecop.projectFilePath">
    <Value>$(MSBuildProjectFullPath)</Value>
  </SonarQubeSetting>
</ItemGroup>

Analyzing languages other than C# and VB

For newer SDK-style projects (used by .NET Core, .NET 5, and later), the SonarScanner for .NET will analyze all file types that are supported by the available language plugins unless explicitly excluded.

For older-style projects, the scanner will only analyze files that are listed in the .csproj or .vbproj project file. Normally this means that only C# and VB files will be analyzed. To enable the analysis of other types of files, include them in the project file.

More specifically, any files included by an element of one of the ItemTypes in this list will be analyzed automatically. For example, the following line in your .csproj or .vbproj file

<Content Include="foo\bar\*.js" />

will enable the analysis of all JS files in the directory foo\bar because Content is one of the ItemTypes whose includes are automatically analyzed.

You can also add ItemTypes to the default list by following these directions.

You can check which files the scanner will analyze by looking in the file .sonarqube-project.properties after MSBuild has finished.

Using SonarScanner for .NET with a proxy On build machines that connect to the Internet through a proxy server you might experience difficulties connecting to SonarQube. To instruct the Java VM to use the system proxy settings, you need to set the following environment variable before running the SonarScanner for .NET:

SONAR_SCANNER_OPTS = "-Djava.net.useSystemProxies=true"

To instruct the Java VM to use specific proxy settings or when there is no system-wide configuration use the following value:

SONAR_SCANNER_OPTS = "-Dhttp.proxyHost=yourProxyHost -Dhttp.proxyPort=yourProxyPort"

Where yourProxyHost and yourProxyPort are the hostname and the port of your proxy server. There are additional proxy settings for HTTPS, authentication and exclusions that could be passed to the Java VM. For more information see the following article: https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html.

You also need to set the appropriate proxy environment variables used by .NET. HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY are all supported. You can find more details here.

Known issues

I have multiple builds in the same pipeline, each of them getting analyzed even if the Run Code Analysis has already been executed

We don’t uninstall the global ImportBefore targets to support concurrent analyses on the same machine. The main effect is that if you build a solution where a .sonarqube folder is located nearby, then the sonar-dotnet analyzer will be executed along your build task.

To avoid that, you can disable the targets file by adding a build parameter:

msbuild /p:SonarQubeTargetsImported=true
dotnet build -p:SonarQubeTargetsImported=true

Last updated

Was this helpful?