Coverage issue for dotnet

The scanner command is working as expected-

sonar-scanner -Dsonar.projectKey=**** -Dsonar.projectName=**** -Dsonar.cs.opencover.reportsPaths=coverage.opencover.xml -Dsonar.cs.vstest.reportsPaths=test_results.trx -Dsonar.branch.name=test

But the dotnet scanner command is having issue while uploading coverage report, issues & unit-tests were reported

dotnet sonarscanner begin /k:"****" /n:"****" /d:sonar.host.url="sonar url" /d:sonar.login="****" /d:sonar.verbose=true /d:sonar.branch.name="test" -d:sonar.cs.vstest.reportsPaths="test_results.trx" /d:sonar.cs.opencover.reportsPaths="coverage.opencover.xml"
dotnet build
dotnet sonarscanner end /d:sonar.login="*****"

Logs related to coverage-
Generic Coverage Report’ skipped because one of the required properties is missing

16:08:18.788 DEBUG: File '/var/lib/jenkins/workspace/***/coverage.opencover.xml' is excluded by the scm ignore settings.
16:08:31.476 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing
16:08:31.478 DEBUG: '[Deprecated] C# Integration Tests Coverage Report Import' skipped because one of the required properties is missing
16:08:31.479 DEBUG: 'VB.NET' skipped because there is no related file in current project
16:08:31.479 DEBUG: 'VB.NET Tests Coverage Report Import' skipped because there is no related file in current project
16:08:31.479 DEBUG: '[Deprecated] VB.NET Integration Tests Coverage Report Import' skipped because there is no related file in current project
16:08:31.480 DEBUG: 'VB.NET Unit Test Results Import' skipped because there is no related file in current project
16:08:31.480 DEBUG: 'Java CPD Block Indexer' skipped because there is no related file in current project
16:08:31.481 DEBUG: Sensors : C# -> C# Tests Coverage Report Import -> C# Unit Test Results Import -> Zero Coverage Sensor
16:08:32.505 INFO: Sensor C# Tests Coverage Report Import [csharp]
16:08:32.505 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir '/var/lib/jenkins/workspace/***/.' and file separator '/'.
16:08:32.507 DEBUG: Pattern matcher extracted prefix/absolute path '/var/lib/jenkins/workspace/***/coverage.opencover.xml' from the given pattern '***.Tests/coverage.opencover.xml'.
16:08:32.507 DEBUG: Pattern matcher returns a single file: '/var/lib/jenkins/workspace/***/coverage.opencover.xml'.
16:08:32.507 DEBUG: The current user dir is '/var/lib/jenkins/workspace/***'.
16:08:32.507 INFO: Parsing the OpenCover report /var/lib/jenkins/workspace/***.Tests/coverage.opencover.xml
16:08:32.769 INFO: Adding this code coverage report to the cache for later reuse: /var/lib/jenkins/workspace/***.Tests/coverage.opencover.xml
16:08:32.771 DEBUG: Analyzing coverage after aggregate found '11' coverage files.
16:08:32.774 INFO: Coverage Report Statistics: 11 files, 0 main files, 0 main files with coverage, 11 test files, 0 project excluded files, 0 other language files.
16:08:32.774 WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting help, please visit our community forum at https://community.sonarsource.com
16:08:32.774 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=269ms

16:08:32.774 WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting help, please visit our community forum at [https://community.sonarsource.com](https://community.sonarsource.com/) 16:08:32.774 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=269ms 16:08:32.774 INFO: Sensor C# Unit Test Results Import [csharp]

Hi Pranavi,

Welcome to the SonarSource community.

You need to build your project, execute tests, and generate code coverage data between the begin and end steps. The end step collects the analysis data generated by the build, the test results, the code coverage, and uploads to SonarQube. So your reportsPaths parameters belong there, instead.


Regards,
Monty

Hi Monty,
Thanks for your reply!!
Yes I tried that too, execution is success but still unable to see Code Coverage report in dashboard. This is the command I am referring to-

dotnet sonarscanner begin /k:“project-name” /d:sonar.host.url=“sonar-url” /d:sonar.login=“key” /d:sonar.branch.name=“test” /d:sonar.cs.opencover.reportsPaths=“Code.Tests/coverage.opencover.xml” /d:sonar.cs.vstest.reportsPaths=“Code.Tests/TestResults/test_results.trx”
dotnet build ‘Code/Code.csproj’
dotnet test ‘Code.Tests/Code.Tests.csproj’ ‘–logger:trx;LogFileName=test_results.trx’ /p:CollectCoverage=true /p:IncludeTestAssembly=true /p:CoverletOutputFormat=opencover ‘/p:ExcludeByFile=**/Microsoft.NET.Test.Sdk.Program.cs’
dotnet sonarscanner end /d:sonar.login=“key”

Hi Pranavi,

The end step collects the analysis data generated by the build, the test results, the code coverage, and uploads to SonarQube. So your reportsPaths parameters belong there, instead.

This is the command that needs these parameters added:
dotnet sonarscanner end /d:sonar.login=“key”


Regards,
Monty

1 Like

Hi Monty,
Yes I tried that too but end is not accepting any parameters other than login.

Test cmd-
dotnet sonarscanner begin /k:“project-name” /d:sonar.host.url=“sonar-url” /d:sonar.login=“key” /d:sonar.branch.name=“test”
dotnet test Code.Tests.csproj
dotnet sonarscanner end /d:sonar.login=“key” /d:sonar.cs.opencover.reportsPaths=“coverage.opencover.xml” /d:sonar.cs.vstest.reportsPaths=“TestResults/test_results.trx”

SonarScanner for MSBuild 5.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
15:11:34.889 15:11:34.889 This setting is not valid in the “end” phase in this version of the C# plugin: sonar.cs.opencover.reportsPaths
15:11:34.889 15:11:34.889 This setting is not valid in the “end” phase in this version of the C# plugin: sonar.cs.vstest.reportsPaths
15:11:34.889 Post-processing failed. Exit code: 1

Hi @pranavi - you need to provide the reportPaths parameters in the begin step, not in the end step. As you can read in the docs (SonarScanner for .NET | SonarQube Docs), all the analysis parameters are provided in the begin step.

Your initial code coverage logs (where you provided the parameters correctly) correctly read the OpenCover report and stated the import problem as a WARN log :

Which is

WARN: The Code Coverage report doesn’t contain any coverage data for the included files.

The paths in the code coverage report are likely wrong, depending on how you generated the reports.

We have a guide for troubleshooting code coverage import problems: [Coverage] Troubleshooting guide for .NET code coverage import

1 Like

Hi @pranavi,

did you manage to find and fix the problem?