Code coverage not shown for .NET 6 projects

Hi,

When we upgraded several projects from .NET Core 3.1 to .NET 6, code coverage is no longer shown in SonarQube UI for these upgraded projects.

The coverage reports are generated using coverlet dotnet tool:

Calculating coverage result...
  Generating report '/azp/agent/_work/17/s/coverage.opencover.xml'
  Generating report '/azp/agent/_work/17/s/coverage.json'
+--------------------------------------+--------+--------+--------+
| Module                               | Line   | Branch | Method |
+--------------------------------------+--------+--------+--------+
| contract                             | 100%   | 100%   | 100%   |
+--------------------------------------+--------+--------+--------+
| service                              | 25.43% | 5.43%  | 43.28% |
+--------------------------------------+--------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 25.43% | 5.43%  | 43.28% |
+---------+--------+--------+--------+
| Average | 62.71% | 52.71% | 71.64% |
+---------+--------+--------+--------+

Afterward SonarQubeAnalyze@4 task is executed and the logs show this:

INFO: Importing 3 Roslyn reports
INFO: Found 3 MSBuild C# projects: 1 MAIN project. 2 TEST projects.
INFO: Sensor C# [csharp] (done) | time=276ms
INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the OpenCover report /azp/agent/_work/17/./s/coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: /azp/agent/_work/17/./s/coverage.opencover.xml
INFO: Coverage Report Statistics: 114 files, 0 main files, 0 main files with coverage, 114 test files, 0 project excluded files, 0 other language files.
WARN: The Code Coverage report doesn't contain any coverage data for the included files. Troubleshooting guide: https://community.sonarsource.com/t/37151

The confusing part is that the logs show 2 TEST projects and 1 MAIN project, but there is actually 1 MAIN project and 1 TEST project.

Our SQ instance is deployed to AKS using the official Helm chart and has 9.2.4.50792 version.
We are using the official SQ tasks in Azure DevOps YAML pipelines. Exactly the same YAML pipeline template is used both for .NET Core 3.1 and .NET 6 projects.

Please let me know if you need more information.

Hello and welcome to the community!

Please give us the following version information:

And we’ll need the logs:

  • please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
    Similar for SonarQubePrepare :
          extraProperties: |
            sonar.verbose=true
  • please give the output of running MSBuild in verbose mode (/v:d)

Also, please tell us:

  • could you please share the coverage report generated by coverlet? I can send you a private message if you don’t want to share this publicly

In addition, please see the following guides:

1 Like

Hello,

  • We are using the official Azure DevOps SQ extension: SonarQube - Visual Studio Marketplace
    Installed version 5.1.1 (Latest)

  • SonarScanner for MSBuild 5.4
    Using the .NET Core version of the Scanner for MSBuild

I will send the output generated by Azure DevOps SQ steps privately. @Andrei_Epure can you please message me as I can’t write a new message probably because of my trust level.

I’ve sent you the private message

only you can access it here

1 Like

problem solved

the issue was that the main project was labeled as test project by the scanner for .net (so the coverage info was ignored) because it was referencing a test assembly (see sonar-scanner-msbuild/IsTestByReference.cs at master · SonarSource/sonar-scanner-msbuild · GitHub).

to solve such a problem you need to explicitly mark the project as non-test

<PropertyGroup>
  <!-- Project is not a test project -->
  <SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>
1 Like

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