Example of c# Azure Devops pipeline that suppress rules

  • SonarQube version sonarqube- - via Azure Devops pipelines.

Trying to suppress rules in c# using MSBuild scannerMode.

I don’t have access to the UI on the SonarQube Virtual Machine so cannot suppress in UI.

Suppress in azure-pipelines.yml
I have tried adding the suppression the SonarQubePrepare task, but this seems to have no effect.

  - task: SonarQubePrepare@5
      SonarQube: 'SonarQube Service Connection'
      scannerMode: 'MSBuild'
      configMode: 'manual'
      projectKey: ${{ parameters.projectKey }}
      projectName: ${{ parameters.projectName }}
      sources: ${{ parameters.sources }}
      extraProperties: |

Using sonar-project.properties
I have tried using sonar-project.properties but the MSBuild scanner rejects that file.

Using SonarQubeSetting Include=
I tried renaming the sonar-project.properties and including it via the SonarQubeSetting, but that didn’t work either.

		<SonarQubeSetting Include="CustomerPlanning.sonar-project.properties">

Can you please provide a working example of the suppressions for the SonarQubePrepare task? All the support issues I have read say to use the UI, but that is not an option for me.

Tried as well in the csproj file:

    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria">
    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria.c1.ruleKey">
    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria.c1.resourceKey">

Got a warning in the UI:

Specifying issue exclusions at module level is not supported anymore. Configure the property ‘sonar.issue.ignore.multicriteria’ and any other issue exclusions at project level.

@gaui could you share the verbose logs for the end step please?

To get this in Azure DevOps you should add the sonar.verbose to the Prepare step e.g.:

- task: SonarQubePrepare@5

      extraProperties: |

Also, just to be clear on what you are trying to achieve:

  • you are trying to disable some rules completely without using the UI
  • some of the rules are Sonar C# analysis rules
  • some are Microsoft analysis rules

Is that correct?

Got it to work by changing the prefix of the exclusions.



Also Roslyn rules are supposed in C# using SuppressMessage.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.