There is a dotnet tool called dotnet-coverage that does this.
Install in on the machine (or your build server, if this is for your pipeline):
dotnet tool install --global dotnet-coverage
Generate your coverage with your preferred tools, and then you can use dotnet-coverage
to merge them all into a single file.
dotnet test files (.coverage):
dotnet-coverage merge *.coverage --recursive --output merged.coverage
dotnet test XML coverage files (.xml):
dotnet coverage merge *.xml --recursive --output coverage.xml --output-format xml
Coverlet (.cobertura.xml):
dotnet-coverage merge *.cobertura.xml --recursive --output merged.cobertura.xml --output-format cobertura
Using in pipeline
To use it in an Azure DevOps pipeline, set up your step like this (this is for Coverlet, but can easily be adjusted):
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet custom'
inputs:
command: custom
custom: coverage
arguments: 'merge *.coverage.xml --recursive --output MergedCoverage.cobertura.xml --output-format xml'
And then publish the merged coverage report:
steps:
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage from MergedCoverage.cobertura.xml'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: MergedCoverage.cobertura.xml