[.NET + GitHub Actions] SonarQube shows 0% coverage despite valid Cobertura report

GitHub

CI system used:

GitHub Actions (ubuntu-latest runner)

Scanner command used:

bash

CopyEdit

dotnet sonarscanner begin \
  /k:"mdog-Mcd.McDog.Kpi" \
  /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
  /d:sonar.host.url="https://sonarqube.mcd.com/" \
  /d:sonar.cs.cobertura.reportsPaths="coverage-report/Cobertura.xml" \
  /d:sonar.coverage.exclusions="**/obj/**,**/Migrations/**" \
  /d:sonar.sources="Docker/Kpi/src" \
  /d:sonar.verbose=true \
  /d:sonar.debug=true

dotnet build Docker/Kpi/Mcd.McDog.Kpi.sln --no-restore

dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

Languages of the repository:

  • C# (.NET 8)
  • Terraform (with exclusions)
  • Python scripts (minimal)

Error observed:

Despite generating valid Cobertura XML and including it in the scanner command, SonarQube reports 0% coverage.

bash

CopyEdit

SonarQube says: “No coverage information found for the files”

However, we verified the coverage report exists and contains:

xml

CopyEdit

<sources>
  <source>Docker/Kpi/src</source>
</sources>

<class name="SampleClass" filename="Mcd.McDog.Kpi.Api/Controllers/TestController.cs" ...
<line number="10" hits="1" branch="false"/>

We also normalize paths with:

bash

CopyEdit

sed -i "s|/home/runner/work/${{ github.repository }}/${{ github.repository }}/Docker/Kpi/src/|Docker/Kpi/src/|g" coverage-report/Cobertura.xml

Steps to reproduce:

  1. GitHub Action runs dotnet test --collect:"XPlat Code Coverage"
  2. Generates .coverage binary file
  3. Runs ReportGenerator:

bash

CopyEdit

reportgenerator -reports:"TestResults/**/coverage.cobertura.xml" -targetdir:"coverage-report" -reporttypes:"Cobertura"
  1. Normalize <source> paths in Cobertura.xml
  2. Execute SonarQube analysis using dotnet scanner
  3. SonarQube shows “0% coverage”

Potential workaround:

None found yet.

We confirmed:

  • coverage-report/Cobertura.xml exists
  • <source> matches /d:sonar.sources
  • <filename> values point to valid .cs files
  • GitHub runner sees those .cs files under the same paths

Please advise:

  • Is there another way to debug why coverage mapping fails?
  • Are there additional logs or verbose flags to enable?
  • Can a mismatch still occur even if paths appear correct?

Thanks in advance,
Sanjeev

Hi there, @Sanjeev_Jhandai

I’m deeply sorry, but the .NET analyzer does not support the cobertura format yet.
You can see the list of supported formats in our documentation page.

That being said, I’m happy to say we have planned to add Cobertura support for later in the year. You can watch, vote for, and subscribe for updates to, the status of the feature on our Public Roadmap.

Denis