Code coverage is showing 0% in sonarqube dashboard for Dotnet core

I’m integrating with Azure Devops Dotnet core application. Im able to see code coverage report in Azurepipelines, but its not showing in sonarqube



For the SonarQube Tasks there is a version 5.x available.

Which Test Framework do you use?
Which Microsoft.NET.Test.Sdk, MSTest.TestAdapter and MSTest.TestFramework do you use?
How do you collect code coverage? Coverlet, Microsoft “Code Coverage”, …?
Which Visual Studio build do you use?
Which files are generated during dotnet test (*.trx, *.coverage, …) and in which directory? See build logs.
Which files are discovered test files are found from SonarQube Run Code Analysis task? In which directories they are searched for? See build logs.

IMHO you can provide a lot more information, please.

P.S.: Starting with Microsoft.NET.Test.Sdk 17.2 we also got issues with “Code Coverage” for netcore3.1. With Coverlet we could resolve them.

"Microsoft.NET.Test.Sdk" Version="16.7.1" 
"Moq" Version="4.16.1" 
"MSTest.TestAdapter" Version="2.1.1" 
"MSTest.TestFramework" Version="2.1.1" 
"coverlet.collector" Version="1.3.0" 

net5.0
Visual Studio Version 16
.trx files are generated while testing

Log details

msbuild\SonarScanner.MSBuild.exe end
2022-11-16T10:00:07.8194270Z SonarScanner for MSBuild 4.8
2022-11-16T10:00:07.8206035Z Using the .NET Framework version of the Scanner for MSBuild
2022-11-16T10:00:07.8694466Z Post-processing started.
2022-11-16T10:00:08.0090823Z 04:00:08.008 Fetching code coverage report information from TFS…
2022-11-16T10:00:08.0107021Z 04:00:08.01 Attempting to locate a test results (.trx) file…
2022-11-16T10:00:08.0535675Z 04:00:08.052 Looking for TRX files in: D:\TFSBuildAgent_work\307\TestResults
2022-11-16T10:00:08.0540049Z 04:00:08.053 The following test results files were found: D:\TFSBuildAgent_work\307\TestResults\TFS2017Admin_PPR-APPTFS02_2022-11-16_03_59_48.trx
2022-11-16T10:00:08.0930582Z 04:00:08.092 No code coverage attachments were found from the trx files.
2022-11-16T10:00:08.1226714Z WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis…
2022-11-16T10:00:08.1228920Z D:\TFSBuildAgent_work\307\s\src\Tests\Tests.csproj, D:\TFSBuildAgent_work\307\s\src\Tests\Tests.csproj
2022-11-16T10:00:08.1709078Z WARNING: File ‘C:\Users\tfs2017admin.nuget\packages\configapibase\1.1.49\contentFiles\any\net5.0\appsettings.Development.json’ is not located under the root directory ‘D:\TFSBuildAgent_work\307\s’ and will not be analyzed.
2022-11-16T10:00:08.1720982Z WARNING: File ‘C:\Users\tfs2017admin.nuget\packages\configapibase\1.1.49\contentFiles\any\net5.0\appsettings.json’ is not located under the root directory ‘D:\TFSBuildAgent_work\307\s’ and will not be analyzed.
2022-11-16T10:00:08.1986069Z Calling the SonarQube Scanner…
2022-11-16T10:00:08.5885681Z INFO: Scanner configuration file: D:\TFSBuildAgent_work_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.9.0\classic-sonar-scanner-msbuild\sonar-scanner-4.2.0.1873\bin..\conf\sonar-scanner.properties

Obviously, your case will be different than ours as with Test-SDK 16.x we had no issues.

In the log of Run SonarAnalysis no coverage files are found, thus please have a look in the test task, if there are coverage files generated - and if, where they are located.