Unable to push code coverage report for a C# project using VSTS task

978 views
Skip to first unread message

goenning

unread,
Feb 8, 2018, 11:31:37 AM2/8/18
to SonarQube
Hi all,

I'm using the recent v4 VSTS Task to push analysis to our SonarQube, but noticed that code coverage is not being shown.

I have this settings on my Prepare Analysis Configuration:

sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml

The code coverage enabled is turned on on my Visual Studio Test Task, it even shows the coverage % on the build page.

During the Run Code Analysis, I can see the file being read by it.

2018-02-08T14:33:12.1268393Z INFO: ------------- Scan MyProject.WebApi
2018-02-08T14:33:12.1424641Z INFO: Initializer GenericCoverageSensor
2018-02-08T14:33:12.1424641Z INFO: Initializer GenericCoverageSensor (done) | time=0ms
2018-02-08T14:33:12.1424641Z INFO: Base dir: F:\Agent01\w\93\s\src\MyProject.WebApi
2018-02-08T14:33:12.1424641Z INFO: Working dir: F:\Agent01\w\93\.sonarqube\out\.sonar\myproject-api_6D593D07-BEF2-4111-BA4C-1E0F2CD3EEA2
2018-02-08T14:33:12.1424641Z INFO: Source paths: <a bunch of .cs files here>
2018-02-08T14:33:12.1424641Z INFO: Source encoding: UTF-8, default locale: en_US
2018-02-08T14:33:12.1424641Z INFO: Index files
2018-02-08T14:33:12.1424641Z INFO: Excluded sources:
2018-02-08T14:33:12.1424641Z INFO: Migrations/*
2018-02-08T14:33:12.1424641Z INFO: Analyzer working directory contains 6 .pb file(s)
2018-02-08T14:33:12.1580892Z INFO: 30 files indexed
2018-02-08T14:33:12.1580892Z INFO: 0 files ignored because of inclusion/exclusion patterns
2018-02-08T14:33:12.1580892Z INFO: Quality profile for cs: ProjectBase
2018-02-08T14:33:12.1737162Z INFO: Sensor C# [csharp]
2018-02-08T14:33:12.1737162Z INFO: Importing analysis results from F:\Agent01\w\93\.sonarqube\out\1\output-cs
2018-02-08T14:33:12.2362444Z INFO: Importing Roslyn report
2018-02-08T14:33:12.2362444Z INFO: Sensor C# [csharp] (done) | time=63ms
2018-02-08T14:33:12.2362444Z INFO: Sensor C# Tests Coverage Report Import [csharp]
2018-02-08T14:33:12.2362444Z INFO: Parsing the Visual Studio coverage XML report F:\Agent01\w\93\s\TestResults\LocalBuildAgent_1 2018-02-08 15_31_58\In\1\LocalBuildAgent_1 2018-02-08 15_31_08.coveragexml
2018-02-08T14:33:12.2987151Z INFO: Adding this code coverage report to the cache for later reuse: F:\Agent01\w\93\s\TestResults\LocalBuildAgent_1 2018-02-08 15_31_58\In\1\LocalBuildAgent_1 2018-02-08 15_31_08.coveragexml
2018-02-08T14:33:12.2987151Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=62ms
2018-02-08T14:33:12.2987151Z INFO: Sensor [Deprecated] C# Integration Tests Coverage Report Import [csharp]
2018-02-08T14:33:12.2987151Z INFO: Sensor [Deprecated] C# Integration Tests Coverage Report Import [csharp] (done) | time=0ms
2018-02-08T14:33:12.2987151Z INFO: Sensor C# Unit Test Results Import [csharp]
2018-02-08T14:33:12.2987151Z INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=0ms
2018-02-08T14:33:12.2987151Z INFO: Sensor Zero Coverage Sensor
2018-02-08T14:33:12.3143518Z INFO: Sensor Zero Coverage Sensor (done) | time=0ms
2018-02-08T14:33:12.3143518Z INFO: Sensor Code Colorizer Sensor
2018-02-08T14:33:12.3143518Z INFO: Sensor Code Colorizer Sensor (done) | time=16ms
2018-02-08T14:33:12.3143518Z INFO: Sensor CPD Block Indexer
2018-02-08T14:33:12.3143518Z INFO: org.sonar.scanner.cpd.deprecated.DefaultCpdBlockIndexer@99e2cb is used for cs
2018-02-08T14:33:12.3143518Z INFO: Sensor CPD Block Indexer (done) | time=0ms

Any thoughts on what could be wrong?

Thanks

sujit...@gmail.com

unread,
Feb 9, 2018, 6:43:47 AM2/9/18
to SonarQube
Hi Goenning,

You will have to convert the coverage report by using the dynamic code coverage tool, you can use a command line task to run the following task just before the end analysis task. I had similar issue in the VSTS which is resolved and now i can see the coverage report in the portal.

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"VisualStudio.coveragexml" "$(coveragefile)"

goenning

unread,
Feb 12, 2018, 10:42:15 AM2/12/18
to SonarQube
Thanks for the suggestion. I've tried that but didn't help. What I noticed is that VSTS task is not reading properly the sonar.cs.vscoveragexml.reportsPaths configuration.
I tried a couple of wrong settings, like:
  • sonar.cs.vscoveragexml.reportsPaths=abc.coveragexml
  • sonar.cs.vscoveragexml.reportsPaths=my.cover
  • # sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
No matter what I do, the task is still picking the original coveragexml from the VS Test task (TestResults\LocalBuildAgent_1 ...)

valeri....@sonarsource.com

unread,
Feb 14, 2018, 4:49:36 AM2/14/18
to SonarQube
Hi,

Could you try again without the sonar.cs.vscoveragexml.reportsPaths property? If this does not work, I would need the verbose logs from the scanner, you could enable them by adding "sonar.verbose=true" in the "prepare analysis" task and attach the full log here.

Thanks,
Valeri


m...@goenning.net

unread,
Feb 15, 2018, 5:24:35 AM2/15/18
to SonarQube
Hey,

The verbose logs helped a lot.
I got message like these for all my classes.

2018-02-14T11:20:22.6805566Z 12:20:22.664 DEBUG: Code coverage will not be imported for the following file outside of SonarQube: C:\s\src\MyProject\Pdf\Elements\Section.cs
2018-02-14T11:20:22.6805566Z 12:20:22.664 DEBUG: Code coverage will not be imported for the following file outside of SonarQube: C:\s\src\MyProject\Pdf\Elements\Page.cs

Although my workdir is actually this:

Build directory: F:\Agent01\w\263

And source is here:

F:\Agent01\w\263\s\src\MyProject\Pdf\Elements\Section.cs

It looks like either:

1) the coverage generated by VSTS has the wrong path 
2) sonar importer is trying to read from an absolute path instead of relative
3) ???

I didn't have the time to look further, I'll give it a go later again. But if you know something that might help, please let me know.

Thanks!
Reply all
Reply to author
Forward
0 new messages