I found that all of these methods has issues, building a large repo with XAML applications, and some old project format *.*proj files. The solution that worked for me was:
- Build the solution with MSBuild
- Download coverlet.collector from NuGet
- Run dotnet test with coverlet specified as the adaptor and --no-build
- Use the ReportGenerator extension to combine the coverage reports
- Publish the code coverage results
One issue in particular was that setting enableCodeCoverage: true
use the MS CoverCoverage.exe which then prevents viewing the nicely formatted results in Azure DevOps
In yaml it looks like:
- task: NuGetCommand@2
displayName: Restore NuGet Packages
inputs:
command: 'restore'
restoreSolution: Path/To/My.sln
feedsToUse: 'select'
vstsFeed: 'MyCompany/PrivateFeed'
includeNuGetOrg: true
- task: MSBuild@1
displayName: 'Build'
inputs:
solution: Path/To/My.sln
msbuildArchitecture: 'x64'
configuration: Release
msbuildArguments: /p:DebugSymbols=true /p:DebugType=portable -m
- task: NuGetCommand@2
displayName: 'Restore Coverlet Adapter'
inputs:
command: custom
restoreDirectory: .\
arguments: 'install coverlet.collector -Version 3.0.3 -ExcludeVersion'
- task: DotNetCoreCLI@2
inputs:
command: test
arguments: Path/To/My.sln --no-build -a $(Build.SourcesDirectory)\coverlet.collector\build\netstandard1.0 --collect:"XPlat Code Coverage"
- task: reportgenerator@4
inputs:
reports: $(Pipeline.Workspace)\**\coverage.cobertura.xml
targetdir: 'coveragereport'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: 'coveragereport/cobertura.xml'
reportDirectory: 'CoverageReport'