Code coverage showing on Azure devops UI where as not showing on sonarcloud


code coverage result were working fine on Window(showing result both on Azure devops UI and sonarcloud as well) but not on Linux (only showing on Azure devops UI but not on sonarcloud)

We choose AGent as Ubuntu

Prepare analysis :

Dotnet test
Argument : –collect:“XPlat Code Coverage”

script :
dotnet tool install -g dotnet-reportgenerator-globaltool

reportgenerator -reports:$(Agent.TempDirectory)//coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coveragereport -reporttypes:‘HtmlInline_AzurePipelines;Cobertura’*

publish code coverage :
Summary file : $(Build.SourcesDirectory)/coveragereport/Cobertura.xml
report directory : $(Build.SourcesDirectory)/coveragereport

after execution of pipeline shows the result:
dotnet test result -
Starting test execution, please wait…
A total of 1 test files matched the specified pattern.
Results File: /home/vsts/work/_temp/_fv-az162-636_2023-09-06_12_52_05.trx


  • /home/vsts/work/_temp/06f71caa-7b01-4820-ab00-49f8caa2c320/coverage.cobertura.xml*

under publish code coverage result:
1. 2023-09-06T12:52:24: Arguments

2023-09-06T12:52:24: -reports:/home/vsts/work/1/s/coveragereport/Cobertura.xml

2023-09-06T12:52:24: -targetdir:/home/vsts/work/_temp/cchtml

2023-09-06T12:52:24: -reporttypes:HtmlInline_AzurePipelines

2023-09-06T12:52:25: Writing report file ‘/home/vsts/work/_temp/cchtml/index.html’

2023-09-06T12:52:25: Report generation took 1.1 seconds

Generated code coverage html report: /home/vsts/work/_temp/cchtml

##[warning]Ignoring coverage report directory with Html content as we are auto-generating Html content

Reading code coverage summary from ‘/home/vsts/work/1/s/coveragereport/Cobertura.xml’

Async Command Start: Publish code coverage

Publishing coverage summary data to TFS server.

Lines- 4116 of 6206 covered.

Branches- 355 of 920 covered.

Modifying Cobertura Index file

Publishing code coverage files to TFS server.

Uploading 176 files

Max dedup parallelism: 192

Building file tree

Uploaded 0 out of 28,946,415 bytes.

Uploaded 28,946,415 out of 28,946,415 bytes.

Associating files

Total files: 176 ---- Associated files: 0 (0%)

File upload succeed.

Published ‘/home/vsts/work/_temp/cchtml’ as artifact ‘Code Coverage Report_2874’

Async Command End: Publish code coverage

Finishing: Publish code coverage from /home/vsts/work/1/s/coveragereport/Cobertura.xml

Under run code analysis shows the result as :
INFO: Parsing the OpenCover report /home/vsts/work/1/s/coveragereport/Cobertura.xml

WARN: Could not import coverage report ‘/home/vsts/work/1/s/coveragereport/Cobertura.xml’ because ‘Missing root element in /home/vsts/work/1/s/coveragereport/Cobertura.xml at line 3’. Troubleshooting guide: [Coverage] Troubleshooting guide for .NET code coverage import

INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=64ms

INFO: Sensor C# Unit Test Results Import [csharp]

INFO: Parsing the Visual Studio Test Results file ‘/home/vsts/work/_temp/_fv-az162-636_2023-09-06_12_52_05.trx’.

INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=102ms

still not showing the code coverge result on sonarcloud. so please help me on this issue

Hey there.

Take a look at this thread:

Hi @Colin,

FYI, I am using classic editor
And I have tried it but giving error for opencover format.

Please help where and what I am missing to get the opencover format result ?

It looks like the report generator you’re using only supports generating opencover in the pro edition (GitHub - danielpalme/ReportGenerator: ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.)

Have you tried the other coverage report generators mentioned in the docs?

Hi Colin,

I just tried with below changes and its working

Prepared analysis

dotnet test
–collect:“XPlat Code Coverage;Format=opencover”

Publish code coverage

on execution of pipline
dotnet test

publish code coverage

run cod analysis

Here I was trying to publish the code coveage to opencover format and it showing the code coverage result on sonarcloud.
–collect:“XPlat Code Coverage;Format=opencover”

Any inputs or suggestions please on the approach above ?

Hey there.

I’m not quite sure what the status is based on your post.

So… it’s working now? Is your coverage displayed in SonarCloud?

yes its working and showing the coverage result on SonarCloud

Hi Colin,

Suggest me the approach I am following is correct or not ?


Hi Colin,

Suggest me the approach I am following is correct or not ?


If you code coverage is being imported correctly, yes, I suggest that the approach you’re following is correct!