Start Free
SonarQube Community Build | DevOps platform integration | Azure DevOps integration | Adding analysis to Azure pipeline | .NET project

Adding analysis to your Azure pipeline for a .NET project

On this page

Before starting, read Azure Pipelines integration overview

Once you have created your project in SonarQube Server and set up feature integration for your project, you can add the SonarQube Server analysis to your Azure build pipeline. 

To create your Azure build pipeline, you can use either YAML or the Azure Classic interface. 

If you need to use a specific scanner version, see Using a specific version of SonarScanner for .NET or CLI.

About the analysis parameter setup

Analysis parameters can be set at different levels: see Configuring the project analysis parameters in Creating and configuring your project. 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 the .NET mode in the Prepare Analysis Configuration task.). 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 Rune Code Analysis task, add a Publish Quality Gate Result task. 

See the YAML file example below. See also our YAML pipeline templates. For information about the SonarQube task inputs, see SonarQube tasks for Azure Pipelines.

YAML file example
trigger:
- master # or the name of your main branch
- feature/*

steps:
 # Checkout the repository 
- checkout: self

 # Disable shallow fetch
  fetchDepth: 0

# Prepare Analysis Configuration task
- task: SonarQubePrepare@7
  inputs:
    SonarQube: '<YourSonarqubeServerEndpoint>'
    scannerMode: 'dotnet'
    projectKey: '<YourProjectKey>'

# Dotnet build task
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'

# Run Code Analysis task
- task: SonarQubeAnalyze@7

# Publish Quality Gate Result task
- task: SonarQubePublish@7
  inputs:
    pollingTimeoutSec: '300'

Using the Classic interface

To add the analysis to your classic build pipeline:

  1. In Azure DevOps Classic interface editor, create or update your build pipeline.
  2. Add a Prepare Analysis Configuration task before your build task:
    • In SonarQube Service Endpoint, select the SonarQube Community Build service connection you created in Adding the SonarQube service connection to your AzDO project in Setting up integration for your project.
    • 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 Community Build analysis to run automatically.
  6. Save your pipeline. 

.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


Was this page helpful?

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

Creative Commons License