C# Code coverage percentage reported in SonarQube not the same as in Visual Studio

  • SonarQube Version: 5774
  • Scanner CLI Version:
  • SonarQube deployed: zip

What are we trying to achieve?

To get the same percentage coverage as in Visual Studio for C# based project

What have you tried so far to achieve this?

  • We have tried dotnet-coreage in the following formats:
    • coverage
    • cobertura
    • xml

Code coverage in Visual Studion 2020 reports coverage with 72% while SonarQube reports 0.5% using the same coverage output.

Could you please help us with some suggestions on how to fix this issue?

Thank you.


Welcome to the community!

First, your SonarScanner CLI version is out of date; the current version is 5.0.1. That said, for a C# project, you should be using the SonarScanner for .NET.

Also 5774 is not a SonarQube version. Can you check the page footer and give is the version you’re running?

And then please try with a current version of SonarScanner for .NET and come back to us if you’re still experiencing a problem.


Thank you Ann for you quick reply. Let me try with your suggested changes.

Apologies for providing the wrong version. This is the version we’re using: ** Developer Edition - Version 9.9 (build 65466) **

1 Like

Hi Ann,

We updated to the latest developer version of SonarQube:

  • Developer Edition
  • Version 10.4.1 (build 88267)

The same issue exists even in this new version. Do you have more ideas we can try?

Here are the command lines we use in our CI/CD pipeline

dotnet sonarscanner begin /k:"CMAWebServices" /d:"sonar.host.url=${SONAR_HOST_URL}" /d:"sonar.login=${SONAR_TOKEN}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet-coverage collect 'dotnet test' -f xml -o 'coverage.xml'
dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage

Thank you,


Hi Pedro,

Could you provide analysis logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d


dotnet build -v:d