Integration Guide
Configuring coverlet.msbuild
The coverlet.msbuild package allows you to integrate code coverage directly into your project's MSBuild lifestyle. It's the ideal choice for developers who want to define coverage rules and thresholds as part of their .csproj configuration.
Why Use MSBuild Integration?
While the collector driver is recommended for its out-of-process nature, the MSBuild package offers unparalleled control over Threshold Enforcement. You can configure your build to fail automatically if coverage drops below a certain percentage—perfect for strict CI/CD pipelines.
Getting Started
dotnet add package coverlet.msbuild
Standard Execution
Run your tests with the CollectCoverage property set to true:
dotnet test /p:CollectCoverage=true
Setting Coverage Thresholds
Enforce a minimum coverage percentage by adding these properties to your project file:
<!-- YourTestProject.csproj -->
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<Threshold>80</Threshold>
<ThresholdType>line,branch,method</ThresholdType>
<ThresholdStat>total</ThresholdStat>
</PropertyGroup>
If the coverage falls below the specified Threshold, the
dotnet test command will return a non-zero exit code, failing your build or CI pipeline.