MSBuild Sonar™Scanner

Configuration

Use the MSBuild Sonar™ task for the “classic” .NET Framework 4.6+ builds. For other .NET related builds, use the dotnet task.

1

Install the MSBuild Sonar™Scanner as described in https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/ Make sure to download the version for .NET Framework 4.6+.

Example projects for MSBuild can be found here.

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.msbuild.SonarMsBuild=path/to/your/msbuild/home
      where SonarMsBuild is the label that can be selected in the task configuration

3

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

  1. Select the Sonar™ MSBuild capability from step 2.

  2. Provide the required Sonar™ project parameters

image-20240906-151748.png
4

Add a MSBuild task to build your build plan:

  1. Select an executable that points to your .NET framework (location of the MSBuild.exe), and not the SonarMSBuild from step 2.

  2. Provide the solution file details in Project File

5

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

  1. Select the Sonar™ MSBuild capability from step 2.

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.