How can PublishCodeCoverageResults@2 work with reportgenerator@5 on Azure DevOps?
The Code Coverage tab on Azure DevOps DOES NOT display the test report, when reportgenerator@5 is used with PublishCodeCoverageResults@2. Here is an example:
- task: DotNetCoreCLI@2
inputs:
command: 'test'
projects: '**/*.Tests.csproj'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage;Format=json,cobertura,lcov,teamcity,opencover" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover'
publishTestResults: true
- task: reportgenerator@5
inputs:
reports: $(Agent.TempDirectory)/**/coverage.cobertura.xml
targetdir: $(Pipeline.Workspace)/coverlet
reporttypes: Cobertura
verbosity: Verbose
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: $(Pipeline.Workspace)/coverlet/Cobertura.xml
However, if I replace PublishCodeCoverageResults@2 with PublishCodeCoverageResults@1, the Code Coverage tab on Azure DevOps does display the report. Here is an example:
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Pipeline.Workspace)/coverlet/Cobertura.xml
How can one get PublishCodeCoverageResults@2 to work with reportgenerator@5?
When I use PublishCodeCoverageResults@2
with reportgenerator@5
, the code coverage report:
When I use PublishCodeCoverageResults@1
with reportgenerator@5
, the code coverage report:
Currently, PublishCodeCoverageResults@2
doesn't support branch and method coverage and there is no details page for each class. According to the comment in the official blog,
the current gap between V1 and V2 (missing line and branch based coverage) is because the V2 does not use the report generator internally. There were issues with report generator for larger repositories and that is one of the reasons to move away from that.
To use the Publish Code Coverage Results v2 task in the pipeline, please use the dotnet 7.0.x task as a pre-requisite in the pipeline. Use the dotnet core task before the Publish Code Coverage v2 task. See the detailed info from Remarks.
# Dotnet core sdk task 7.0.x
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 7.0.x'
inputs:
version: 7.0.x