.NET project

Adding the SonarQube Cloud analysis to your Azure build pipeline for Net projects.

The setup is different depending on whether you use YAML or the Azure Classic interface.

circle-info
  • The use of the Classic editor is not always possible (e.g. if your code is stored on GitHub).

  • If you use YAML, SonarSource can provide you with YAML templates or code examples.

Before you start

Before you begin, read Azure Pipelines integration overview.

The prerequisites are:

If you need to use a specific scanner version, see Using various features.

circle-info

Analysis parameters can be set at different levels, see Configuring the project analysis parameters. When creating your pipeline, you will have to enter the project key and you may also enter the project version and name. For more information about these task inputs, see Task inputs specific to the .NET mode. You may define additional parameters in this task. In that case, these parameters have precedence over parameters defined at the project or global level.

Using YAML

Add the following SonarQube tasks to your YAML pipeline:

  1. Before your build task, add a Prepare Analysis Configuration task.

  2. After your build task, add a Run Code Analysis task.

  3. After the Run Code Analysis task, add a Publish Quality Gate Result task.

See the YAML file example below. Also, see the YAML pipeline templatesarrow-up-right. For information about the SonarQube task inputs, see SonarQube tasks for Azure Pipelines.

circle-info

Make sure the SonarQube task version used in your YAML file is the correct one. For example, in SonarQubePrepare@7, 7 should correspond to the version of the Azure DevOps Extension you’re using.

chevron-rightYAML file examplehashtag

Using the Classic editor

To add the analysis to your classic build pipeline:

  1. In the Azure DevOps Classic editor, create or update your build pipeline.

  2. Add a Prepare Analysis Configuration task before your build task:

    • In SonarQube Server Service Endpoint, select the SonarQube service connection you created during setup. See the Setting up Azure integration for your project page for more information about adding a connection.

    • Under Choose a way to run the analysis, select Integrate with MSBuild.

    • In the Project key field, enter your project key.

    • Optionally, enter the project name and version.

  3. Add a new Run Code Analysis task after your build task.

  4. Add a new Publish quality gate Result on your build pipeline summary.

  5. Ensure that the pipeline runs automatically for all the branches you want:

    • Under the Triggers tab of your pipeline, select Enable continuous integration and select all the branches for which you want SonarQube Server analysis to run automatically.

  6. Save your pipeline.

Configuring your scanner

If you're using the .NET scanner to complete the analysis, see the Configuring the scanner for NET page for language-specific details.

There's also an article about running Multi-language analysis for select languages when the sonar.scanner.scanAll parameter is enabled via the extraProperties listed in your Prepare Analysis Configuration task.

There's also an article about running Prepare Analysis Configuration task.

.Net guides on the Sonar Community forum

We’ve prepared some guides on the Community Forum to help you with your .NET project.

.NET Configuration

.NET and Code coverage

Last updated

Was this helpful?