which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube - 7.6
Scanner - sonar-scanner-msbuild-4.5.0.1761-net46
Plugin - sonar-csharp-plugin-7.10.0.7896
Code Coverage File generated by - Visual Studio 2017
what are you trying to achieve
Import Code Coverage Results
SonarScanner.MSBuild.exe begin /k:“Name” /n:“Name” /d:sonar.host.url=“http://url” /d:sonar.login=“login” /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\VisualStudio.coveragexml"
I have opened the file VisualStudio.coveragexml in Notepad and in a browser and it shows as a valid XML file.
Getting the error:
ERROR: Error during SonarQube Scanner execution
ERROR: Error while parsing the XML file: C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml
INFO: ------------------------------------------------------------------------
The SonarQube Scanner did not complete successfully
10:21:28.283 Creating a summary markdown file…
10:21:28.289 Post-processing failed. Exit code: 1
I have attached an image of the coverage file the file.
I have changed the encoding of the file to be UTF-8.
I got the following error now:
ERROR: Error during SonarQube Scanner execution
ERROR: Missing root element in C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml at line 1
ERROR:
The SonarQube Scanner did not complete successfully
11:42:16.417 Creating a summary markdown file…
11:42:16.425 Post-processing failed. Exit code: 1
Based on this issue raised against the vstest repo, I think the SonarSource docs no longer describe the approach recommended by Microsoft.
Does it work if you omit the command "%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output: **"%CD%\VisualStudio.coverage"**
and add the /enableCodeCoverage argument to the vstest.console.exe instead?
thanks. That helped.
I managed to run the scan with no errors.
But I don’t see any code coverage numbers added. And the percentage still remains at 0.0%.
If I import the Unit Tests, I managed to see 112 unit tests showing in the dashboards.
So my question is:
How is the Code Coverage Results reflected in the Dashboard? It is just at the %?
Looking at my coveragexml file it is showing some coverage that I don’t see reflected on the Dashboard.
I am using the command: SonarScanner.MSBuild.exe begin /k:"ProjectName" /v:"1.2" /d:sonar.host.url="http://xx.xx.xx.x/sonar" /d:sonar.cs.vstest.reportsPaths="%CD%\TestResults\*.trx" /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\TestResults\Visual.coveragexml"
You should see a percentage coverage figure on the dashboard. If you drill down to view the product code you will also see green and red bars showing which lines are covered, as in the screen shot below.
Trying running the analysis specifying /d:sonar.verbose=true on the command line to increase the logging level and look at the console output for the end step. If the import is working correctly you would expect to see output like the following:
13:23:38.857 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:23:38.858 INFO: Parsing the Visual Studio coverage XML report d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.861 INFO: Adding this code coverage report to the cache for later reuse: d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.864 DEBUG: Found some coverage info for the file 'D:\support\Scanner\coveragebug\ConsoleApp1\ConsoleApp1\Program.cs'.
13:23:38.865 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=8ms
I added the verbose options but don’t get that result:
13:42:41.007 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:42:41.010 INFO: Parsing the Visual Studio coverage XML report C:\Users\rv6811
5\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\TestResults\VisualS
tudio.coveragexml
13:42:41.267 INFO: Adding this code coverage report to the cache for later reuse
: C:\Users\rv68115\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\Te
stResults\VisualStudio.coveragexml
13:42:41.267 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time
=260ms
That suggests the C# test sensor can’t match any of the files listed in the coverage XML to product files it has analyzed. Could you double-check that the coverage file contains information about product files appear in SonarQube? (the coverage file may contain coverage information about test files too, but that coverage information will not be uploaded).
Also, can you repro this with a small solution that you are able to share?
I tried it locally and the coverage data was uploaded as expected.
[Update: BTW I’ve update our documentation to reflect the Mircosoft recommendations]
Hi Duncan,
sonarqube-8
Scanner - sonar-scanner-msbuild-4.5.0.1761-net46
Plugin - sonar-csharp-plugin-7.17.0.9346
Code Coverage File generated by - Visual Studio 2019
i try to run vstest.console.exe and i got output like that
after that I collect the codecoverage using that C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools>CodeCoverage.exe collect /output:"C:\Sonar\DemoProject\TestResults\MyWebApp.coverage
but did not generated the .xml file or .coveragexml file
could you help me i stuck last 2 days
now I got the code Coverage using OpenCover Tool
step
1.add the opencover,Nunit,Nunit.consoleRunner,Nunit3TestAdapter after that execute Nunit.console.exe like that