2
votes

I have an Azure build pipeline with VSTest task that generates code coverage as '.coverage' format. I need to publish this back to the 'Code Coverage' tab in the build result page. Only the download code coverage result is available. How to publish code coverage using '.coverage' file?

enter image description here

I already tried the ReportGenerator tool but when I pass the '.coverage' file to the tool as the report file it gives back the coverage report as zero coverage. When I open the coverage file using visual studio it shows the coverage.

1
you could publish the results with logging commands. Please check out ##vso[task.addattachment]value, ##vso[task.uploadsummary]local file path and ##vso[task.uploadfile]local file path. Maybe it solves your problem. You could use this commands inside a inline powershell script. Make sure that the paths to the report files are correct.Mar Tin

1 Answers

0
votes

I had the same question and just figured it out. I run the testing with MsBuild from a simple Exec-task and have embedded the logging command as a Message-task. Of course you can produce the same output using PowerShell or something else.

<?xml version="1.0" encoding="utf-8"?>
<Project 
  ToolsVersion="14.0" 
  DefaultTargets="ReportCoverage" 
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  ..

  <Target Name="ReportCoverage">

    ..

    <ItemGroup>
      <CoverageResults Include="$(BinDir)\Reports\*.coverage" />
    </ItemGroup>

    <Message 
      Text="##vso[task.addattachment type=Distributedtask.Core.CodeCoverage;name=CodeCoverage;]$(CoverageResults)" 
      Importance="High" 
      Condition="'%(CoverageResults.Identity)' != ''"/>
  </Target>
</Project>

enter image description here