4

I’m trying to run C# Code Coverage Results Import but get error on the last step. I created .coveragexml file (named test.coveragexml) via visual studio (TEST -Analyze Code Coverage- All Tests), saved it in the project directory. Run the following command at CMD:

  1. C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe begin /k:MyProject /n: MyProject /v:1.0 /d:sonar.cs.vscoveragexml.reportsPaths=D:\sTFS\24115\Sources\ MyProject \Source*.coveragexml /d:sonar.verbose=true
  2. Build (via visual studio)
  3. C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe end

For the last step, I’m getting this error:

10:09:29 AM  ERROR: Error during Sonar runner execution
10:09:29 AM  ERROR: Unable to execute Sonar
10:09:29 AM  ERROR: Caused by: Error while parsing the XML file: D:\sTFS\24115\S
ources\SystemMapping\Source\test.coveragexml
10:09:29 AM  ERROR: Caused by: Unexpected character '?' (code 65533 / 0xfffd) in
 prolog; expected '<'
10:09:29 AM   at [row,col {unknown-source}]: [1,1]
10:09:29 AM  ERROR:
10:09:29 AM  ERROR: To see the full stack trace of the errors, re-run SonarQube
Runner with the -e switch.
10:09:29 AM  ERROR: Re-run SonarQube Runner using the -X switch to enable full d
ebug logging.
10:09:29 AM  The sonar-runner did not complete successfully
Post-processing failed. Exit code: 1    

Cannot find any character '?' at the file... From the log:

M  10:09:29.021 INFO  - Sensor org.sonar.plugins.csharp.CSharpSensor@5945ac done: 12370 ms
10:09:29 AM  10:09:29.021 INFO  - Sensor org.sonar.plugins.csharp.CSharpCodeCoverageProvider$CSharpCoverageReportImportSensor@ed32df...
10:09:29 AM  10:09:29.104 INFO  - Parsing the Visual Studio coverage XML report D:\sTFS\24115\Sources\SystemMapping\Source\test.coveragexml
10:09:29 AM  10:09:29.110 DEBUG - Release semaphore on project : org.sonar.api.resources.Project@101ba81[id=37975,key=SystemMapping,qualifier=TRK], with key batch-SystemMapping
10:09:29 AM  INFO: ------------------------------------------------------------------------
10:09:29 AM  INFO: EXECUTION FAILURE
10:09:29 AM  INFO: ------------------------------------------------------------------------
10:09:29 AM  Total time: 21.544s
10:09:29 AM  Final Memory: 13M/121M
10:09:29 AM  INFO: ------------------------------------------------------------------------
10:09:29 AM  Process returned exit code 1
10:09:29 AM  Creating a summary markdown file...
Process returned exit code 1
Pascal Berger
  • 4,262
  • 2
  • 30
  • 54
shani
  • 51
  • 1
  • 7
  • What is the encoding of your `test.coveragexml` file? Could you send the first few bytes (not characters) of it? The code coverage parser expects it to be in UTF-8, and the '?' character is likely to be part of the Byte Order Mark (BOM) sequence. – Dinesh Bolkensteyn Dec 22 '15 at 08:44
  • Also please mention how you generate this XML file, and also let us know if removing the BOM solves the issue. – Dinesh Bolkensteyn Dec 22 '15 at 08:44
  • Hi, you right, the file encoding was UCS-2, I convert it to UTF-8 without BOM and run all the command again. This time I got an error: "Missing root element in D:\sTFS\24115\Sources\SystemMapping\Source\build_VTFS-03-41-08 2015-12-23 18_20_49.coveragexml at line 1". I generate the file manually from VS, as i wrote abow (TEST -Analyze Code Coverage- All Tests, saved it in the project directory.) I upload the file to here: [link] (http://www.filedropper.com/buildvtfs-03-41-082015-12-23182049_1) – shani Dec 23 '15 at 17:42

2 Answers2

1

Finally I succeeded to create code coverage analysis!

  1. Moved the MSBuild.SonarQube.Runner to the same root directory as my project
  2. Switched to OpenCover coverage xml and worked by the command specify here -
  3. Ran the command from Visual Studio Command Prompt

Here is the commands I execute (with 2 unit test dll’s): D:\SonarQube\bin\MSBuild.SonarQube.Runner.exe begin /k:MyProject /n: MyProject /v:1.0 /d:sonar.cs.opencover.reportsPaths="D:\SonarQube\6.5\NP\ MyProject \Source\opencover*.xml" /d:sonar.verbose=true

Build MyProject

"C:\OpenCover\OpenCover.Console.exe" -output:"D:\SonarQube\6.5\NP\ MyProject \Source\opencover1.xml" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"D:\SonarQube\6.5\NP\ MyProject \Source\ MyProject.Test\bin\Debug\ MyProject.Test.dll"

"C:\OpenCover\OpenCover.Console.exe" -output:"D:\SonarQube\6.5\NP\ MyProject \Source\opencover2.xml" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"D:\SonarQube\6.5\NP\ MyProject \Source\ MyProject.test\bin\Debug\ MyProject.test.dll"

D:\SonarQube\bin\MSBuild.SonarQube.Runner.exe end > log.txt

Hope it will help others :)

shani
  • 51
  • 1
  • 7
0

Your code coverage report format (starting with <CoverageDSPriv>) is not yet supported: https://jira.sonarsource.com/browse/SONARNTEST-3

In the meantime, follow the instructions on this page to get Visual Studio code coverage imported in SonarQube: http://docs.sonarqube.org/x/CoBh

Dinesh Bolkensteyn
  • 2,971
  • 1
  • 17
  • 20
  • I tried the flow as described in : http://docs.sonarqube.org/x/CoBh, strange, but the collect command ("%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:"%CD%\VisualStudio.coverage") allways stuck. Ican see that it's creating a VisualStudio.coverage file that weighs 1kb. When "killing" the proccess and try to open the file, i get an error: Exception was thrown: Code Coverage Analysis engine threw exception(s): Coverage file "D:\sTFS\24115\Sources\SystemMapping\Source\VisualStudio.coverage" is invalid or corrupt. How should I procceed? – shani Dec 24 '15 at 10:10
  • Hi, I manage to get .coveragexml file as expected. The end command is finished successfully but no code coverage is shown on the dashboard. From the log: ‘Code coverage will not be imported for the following file outside of SonarQube: D:\sTFS\24115\Sources\SystemMappingTestShani\Source\SystemMappingClient.Test\AspectTests.cs’ – shani Jan 04 '16 at 16:31
  • The coverage report generation and Sonar Analysis are running from the same directory: reportsPaths=D:\sTFS\24115\Sources\SystemMappingTestShani\Source\VisualStudio.coveragexml analyze /output:D:\sTFS\24115\Sources\SystemMappingTestShani\Source\VisualStudio.coveragexml D:\sTFS\24115\Sources\SystemMappingTestShani\Source\VisualStudio.coverage link for the log file: [http://www.filedropper.com/log_1] – shani Jan 04 '16 at 16:31