Importing coverage from .coveragexml file


I’m using SonarQube 8.5 (Community edition) with SonarScanner 4.4 (for MSBuild) to analyze my project (an ASP.NET application on .NET Framework 4.6).
On my local computer, I have VS 2017 Enterprise from which I generate and export coverage files (both via IDE and via batch script that invokes CodeCoverage directly).
I’ve managed to analyze my project’s code base and get the code coverage displayed in the SonarQube’s server (coverage is >0%).

Now, I’m trying to display the same results on a computer that has VS 2017 (or VS 2019) Community edition. I have the .covergexml file generated on my local computer (the Enterprise version) and SonarQube and SonarScanner are also up and running.
However, when I run the same script, the codebase is analyzed and displayed, but coverage isn’t (it remains 0%)

This is the batch script I’m using to run the analysis:

SonarScanner.MSBuild.exe begin /k:"Test" /n:"Test" /v:1.0 /d:sonar.scm.disabled=true /d:sonar.cs.vscoveragexml.reportsPaths="(AbsolutePath)\TestCoverage.coveragexml"
MSBuild.exe /t:Rebuild
SonarScanner.MSBuild.exe end

I’ve placed that script into the root folder of my project (the same folder where the .sln file is) and the process of analysis doesn’t throw any errors. It also contains a line stating that Visual Studio coverage file is being parsed (after the rebuild step has finished)

The same script works on the computer with VS Enterprise, but not on the one with Community edition.

My question is - do I need VS Enterprise to be able to display code coverage in SonarQube, and if not, what am I doing wrong?

Thank you in advance

Hello @NDraskovic,

Welcome to the SonarSource community forum :wave:. We hope you’ll enjoy it.

No you don’t need VS Enterprise. This should work with any VS environment.

I can’t be certain, but I strongly suspect that the absolute source file paths in the coverage file do not correspond to the real path of the files on the file system of the 2nd machine. To confirm, please verify the paths in your TestCoverage.coveragexml file…

If that’s the confirmed root cause, the reason is I guess that you generated the coverage on the 1st machine, copied it on the 2nd and then tried to analyze with coverage on that 2nd machine. This is not the right way to do things (because of the potential path problem but also because you are never sure that the coverage file is aligned with the source files on the local machine).

The right way is to regenerate the coverage file every time your run the build and analysis script, and therefore you should modify your script to include a test coverage execution step after the MSBuild step.
See [Coverage & Test Data] Generate Reports for C#, for some help if needed

If you still run into trouble after this, please send me the logs of your script, preferable run in debug (add /d:sonar.verbose=true to your SonarScanner.MSBuild.exe executions)


Hello @OliverK

Thank you for your response, you are right, the problem was in the paths within the coverage file.
We will try to find some other way to distribute these results, probably by giving access to the SonarQube server to all interested/authorized members.

Thank you again for your response

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