danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.59k stars 281 forks source link

Conversion from 'Visual Studio' coverage format (.coverage) to any other formats is not working #306

Closed ganeshpande closed 4 years ago

ganeshpande commented 4 years ago

Conversion from 'Visual Studio' coverage format (.coverage) to any other formats is not working -- the generated output formats (Cobertura, Xml, HtmlInline_AzurePipelines) do not have any coverage information. Please see the attached for the ReportGenerator task logs from my Azure Pipeline run.

2020-01-06T08:41:09.9322747Z ##[section]Starting: ReportGenerator 2020-01-06T08:41:09.9490062Z ============================================================================== 2020-01-06T08:41:09.9490116Z Task : ReportGenerator 2020-01-06T08:41:09.9490162Z Description : ReportGenerator converts coverage reports generated by OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats. 2020-01-06T08:41:09.9490187Z Version : 4.4.0 2020-01-06T08:41:09.9490211Z Author : Palmmedia 2020-01-06T08:41:09.9490255Z Help : [More Information](https://github.com/danielpalme/ReportGenerator) 2020-01-06T08:41:09.9490278Z ============================================================================== 2020-01-06T08:41:10.2493259Z [command]"C:\Program Files\dotnet\dotnet.exe" *MASKED*\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.4.0\tools\netcoreapp2.1\ReportGenerator.dll -reports:*MASKED*\_work\_temp\**\*.coverage -targetdir:*MASKED*\ReportGeneratorIssue\CoverageReport1 -reporttypes:Cobertura;Xml;XmlSummary;HtmlInline_AzurePipelines -sourcedirs:*MASKED*\_work\4\s\unit-testing-using-dotnet-test -historydir: -plugins: -assemblyfilters:+* -classfilters:+* -filefilters:+* -verbosity:Verbose -tag:20200106.7_#28198 2020-01-06T08:41:10.3234022Z 2020-01-06T14:11:10: Arguments 2020-01-06T08:41:10.3244657Z 2020-01-06T14:11:10: -reports:*MASKED*\_work\_temp\**\*.coverage 2020-01-06T08:41:10.3244844Z 2020-01-06T14:11:10: -targetdir:*MASKED*\ReportGeneratorIssue\CoverageReport1 2020-01-06T08:41:10.3244957Z 2020-01-06T14:11:10: -reporttypes:Cobertura;Xml;XmlSummary;HtmlInline_AzurePipelines 2020-01-06T08:41:10.3245007Z 2020-01-06T14:11:10: -sourcedirs:*MASKED*\_work\4\s\unit-testing-using-dotnet-test 2020-01-06T08:41:10.3251452Z 2020-01-06T14:11:10: -historydir: 2020-01-06T08:41:10.3251526Z 2020-01-06T14:11:10: -plugins: 2020-01-06T08:41:10.3251566Z 2020-01-06T14:11:10: -assemblyfilters:+* 2020-01-06T08:41:10.3251630Z 2020-01-06T14:11:10: -classfilters:+* 2020-01-06T08:41:10.3252195Z 2020-01-06T14:11:10: -filefilters:+* 2020-01-06T08:41:10.3252329Z 2020-01-06T14:11:10: -verbosity:Verbose 2020-01-06T08:41:10.3252431Z 2020-01-06T14:11:10: -tag:20200106.7_#28198 2020-01-06T08:41:10.4694307Z 2020-01-06T14:11:10: Executable: *MASKED*\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.4.0\tools\netcoreapp2.1\ReportGenerator.Core.dll 2020-01-06T08:41:10.4697062Z 2020-01-06T14:11:10: Working directory: *MASKED*\_work\4\s 2020-01-06T08:41:10.4848853Z 2020-01-06T14:11:10: Settings 2020-01-06T08:41:10.4856829Z 2020-01-06T14:11:10: { "NumberOfReportsParsedInParallel": 1, "NumberOfReportsMergedInParallel": 1, "MaximumNumberOfHistoricCoverageFiles": 100, "RenderPngFallBackImagesForHistoryCharts": false, "CachingDurationOfRemoteFilesInMinutes": 10080, "DisableRiskHotspots": false } 2020-01-06T08:41:10.4857017Z 2020-01-06T14:11:10: { "MetricThresholdForCyclomaticComplexity": 30, "MetricThresholdForCrapScore": 15, "MetricThresholdForNPathComplexity": 200 } 2020-01-06T08:41:10.4972601Z 2020-01-06T14:11:10: Loading report '*MASKED*\_work\_temp\331ad181-bc73-4450-abdb-eb0ecd849815\ganesp_GANESHDT_2020-01-06.14_11_02.coverage' 1/2 in memory 2020-01-06T08:41:10.5006242Z 2020-01-06T14:11:10: Finished parsing *MASKED*\_work\_temp\331ad181-bc73-4450-abdb-eb0ecd849815\ganesp_GANESHDT_2020-01-06.14_11_02.coverage... 2020-01-06T08:41:10.5006613Z 2020-01-06T14:11:10: Loading report '*MASKED*\_work\_temp\ganesp_GANESHDT_2020-01-06_14_11_05\In\GANESHDT\ganesp_GANESHDT_2020-01-06.14_11_02.coverage' 2/2 in memory 2020-01-06T08:41:10.5009477Z 2020-01-06T14:11:10: Finished parsing *MASKED*\_work\_temp\ganesp_GANESHDT_2020-01-06_14_11_05\In\GANESHDT\ganesp_GANESHDT_2020-01-06.14_11_02.coverage... 2020-01-06T08:41:10.5009944Z 2020-01-06T14:11:10: Parsing of 2 files completed. 2020-01-06T08:41:10.5020002Z 2020-01-06T14:11:10: Coverage report parsing took 0.0 seconds 2020-01-06T08:41:10.5145548Z 2020-01-06T14:11:10: Initializing report builders for report types: Cobertura, Xml, XmlSummary, HtmlInline_AzurePipelines 2020-01-06T08:41:10.5183667Z 2020-01-06T14:11:10: Analyzing 0 classes 2020-01-06T08:41:10.5184192Z 2020-01-06T14:11:10: Creating summary 2020-01-06T08:41:10.5265146Z 2020-01-06T14:11:10: Writing report file '*MASKED*\ReportGeneratorIssue\CoverageReport1\Cobertura.xml' 2020-01-06T08:41:10.5379426Z 2020-01-06T14:11:10: Writing report file '*MASKED*\ReportGeneratorIssue\CoverageReport1\index.htm' 2020-01-06T08:41:10.5901424Z 2020-01-06T14:11:10: Writing report file '*MASKED*\ReportGeneratorIssue\CoverageReport1\Summary.xml' 2020-01-06T08:41:10.5905728Z 2020-01-06T14:11:10: Writing report file '*MASKED*\ReportGeneratorIssue\CoverageReport1\Summary.xml' 2020-01-06T08:41:10.5913044Z 2020-01-06T14:11:10: Report generation took 0.1 seconds 2020-01-06T08:41:10.6185631Z ##[section]Finishing: ReportGenerator

danielpalme commented 4 years ago

*.coverage files are not in XML format. You have to convert them to XML in order to parse them with ReportGenerator (or use another coverage tool (e.g. coverlet, OpenCover, etc.)).

You can convert to XML with CodeCoverage.exe .
CodeCoverage.exe is part of this Microsoft.CodeCoverage NuGet package. To generate the XML file you can use the following command:

%UserProfile%\.nuget\packages\microsoft.codecoverage\XYZ\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:DynamicCodeCoverage.coveragexml DynamicCodeCoverage.coverage
danielpalme commented 4 years ago

The latest release 4.4.1 will show a warning if you are trying to parse a not supported binary file with extension ".coverage".

msrinivascharan commented 2 years ago

*.coverage files are not in XML format. You have to convert them to XML in order to parse them with ReportGenerator (or use another coverage tool (e.g. coverlet, OpenCover, etc.)).

You can convert to XML with CodeCoverage.exe . CodeCoverage.exe is part of this Microsoft.CodeCoverage NuGet package. To generate the XML file you can use the following command:

%UserProfile%\.nuget\packages\microsoft.codecoverage\XYZ\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:DynamicCodeCoverage.coveragexml DynamicCodeCoverage.coverage

Thank you.

MS-Manikandan commented 2 years ago

Hi @danielpalme , I have a Issue in converting the visual studio coverage file to coveragexml file in the azure devops build pipelines through the below powershell script task and gave Error: Error: The following coverage file is either corrupt or is not valid: but if I execute manually on the build machine it worked. I am downloading this coverage file from the azure devops log store by invoking the rest api and it downloaded the file and I could locate it. could you help us how to convert the coverage file to coverage xml file in the build pipelines the right way.

$coverageFile="$(Common.TestResultsDirectory)\$(build.buildid).coverage"
$xmlFile="$(Common.TestResultsDirectory)\$(build.buildid).coveragexml"
$enterpriseCodeCoverage="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
$codeCoverageNuget="$env:USERPROFILE\.nuget\packages\microsoft.codecoverage\17.0.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe"

if([System.IO.File]::Exists($codeCoverageNuget)-eq $true) 
{
    Write-Host "Code coverage.exe nuget package exists $env:USERPROFILE\.nuget\packages\microsoft.codecoverage\17.0.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe"

& $codeCoverageNuget analyze /output:"$($xmlFile)" "$($coverageFile)"
} 

else {
    Write-Host "Code coverage.exe nuget package DOESN'T  exists!!!! $env:USERPROFILE\.nuget\packages\microsoft.codecoverage\17.0.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe"
}
danielpalme commented 2 years ago

@ManikandanMani I'm sorry but I don't know why this is not working for you.

Does this line of your script fail?

& $codeCoverageNuget analyze /output:"$($xmlFile)" "$($coverageFile)"

What do you mean by "if I execute manually on the build machine it worked"? Do you use a local build agent?

MS-Manikandan commented 2 years ago

Does this line of your script fail?

Yes, it did fail on the pipelines.

& $codeCoverageNuget analyze /output:"$($xmlFile)" "$($coverageFile)"
& $codeCoverageNuget analyze /output:"$xmlFile" "$coverageFile"
The above two commands failed on pipelines, I got to see this failed by checking the event viewer 
Error: Error: The following coverage file is either corrupt or is not valid:  XXX\_work\249\TestResults\10080.coverage

What do you mean by "if I execute manually on the build machine it worked"? Do you use a local build agent?

I meant to say that I logged into to the agent machine, and executed this ps script and it worked there, and yes I do use local build agent.

And I even tried using the vs enterprise code coverage path instead of the nuget package code coverage path, run the similar script on commandLine (cmd) build task but both didn't worked on the pipeline.

MS-Manikandan commented 2 years ago

I fixed it, I found out that the downloaded file was corrupted and hence it couldn't convert.

sathishreddy48 commented 1 year ago

I've converted a sample test project using CodeCoverage.exe , in the converted XML I could see wrong metrics. Original file sample.coverage.txt Converted file DynamicCodeCoverage.coveragexml.txt Block coverage is showing 100 % here are the actual metrics image

kahuz commented 1 year ago

@sathishreddy48 I had a similar issue and received the response below. https://github.com/microsoft/codecoverage/issues/18#issuecomment-1465720936

I hope this helps.