dotnet Sonar™Scanner

Configuration

Use the Sonar™Scanner for dotnet task to analyze

  • .NET 5+ projects

  • .NET Core Global Tool

  • .NET Core 3.1

  • .NET Core 2.1

If you need to analyze a “classic” .NET Framework 4.6+ project, use the MSBuild Sonar™Scanner task.

1

Install and configure the SonarQube™ Scanner as described in https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/ Make sure to download the appropriate version for your dotnet project.

The task works as well with the .NET Core Global Tool, read the note on step 3 and 5.

2

Configure Build Agent Capability

  1. [local/remote agent] in Bamboo UI

  2. [remote agent] in the amboo-agent-home/bin/bamboo-capabilities.properties file

    1. define capability system.builder.dotnet.Dotnet=path/to/your/dotnet/home
      where Dotnet is the label that can be selected in the task configuration

3

Add a Sonar™ Scanner for dotnet - Begin Analysis task to your build plan

  1. Select the Dotnet Home Path capability from step 2.

  2. Configure the path to your SonarScanner.MSBuild.dll

    1. for .NET Core Global Tool

      1. use sonarscanner instead the path to the DLL

      2. ensure the .dotnet/tools folder is on the path, or add it as environment variable

  3. Provide the required Sonar™ project parameters

4

Add a Script or Command task to build your build plan. Configure it to build your project. A minimal example may look like:

5

Add a Sonar™ Scanner for dotnet - End Analysis task to your build plan

  1. Select the Dotnet Home Path capability from step 2.

  2. Configure the path to your SonarScanner.MSBuild.dll

    1. for .NET Core Global Tool

      1. use sonarscanner instead the path to the DLL

      2. ensure the .dotnet/tools folder is on the path, or add it as environment variable

6

Setup test coverage: 

  • run the coverage report generator after the build phase but right before the Sonar™Scanner dotnet end step.

  • You can find more information on how to do this for various build types in the Wiki.

Tips & Troubleshooting

On SonarQube™ versions older than 9.3 you might encounter this error:

  • error 07-Jan-2022 14:50:44 Invalid project key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.

Update your tasks and enable option "Override branch character replacement" with the "-" character as value.

 

 

SONAR™, SONARQUBE™ and SONARCLOUD™ are independent and trademarked products and services of SonarSource SA: see sonarsource.com, sonarqube.org, sonarcloud.io.