![]() |
VOOZH | about |
dotnet add package coverlet.msbuild --version 10.0.1
NuGet\Install-Package coverlet.msbuild -Version 10.0.1
<PackageReference Include="coverlet.msbuild" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageVersion Include="coverlet.msbuild" Version="10.0.1" />Directory.Packages.props
<PackageReference Include="coverlet.msbuild"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>Project file
paket add coverlet.msbuild --version 10.0.1
#r "nuget: coverlet.msbuild, 10.0.1"
#:package coverlet.msbuild@10.0.1
#addin nuget:?package=coverlet.msbuild&version=10.0.1Install as a Cake Addin
#tool nuget:?package=coverlet.msbuild&version=10.0.1Install as a Cake Tool
In this mode, Coverlet doesn't require any additional setup other than including the coverlet.msbuild NuGet package in the unit test project. It integrates with the dotnet test infrastructure built into the .NET Core CLI and when enabled, will automatically generate coverage results after tests are run.
If a property takes multiple comma-separated values please note that you will have to add escaped quotes around the string like this: /p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*\", /p:Include=\"[coverlet.*]*,[*]Coverlet.Core*\", or /p:CoverletOutputFormat=\"json,opencover\".
To achieve same behavior above using powershell you need to use the verbatim argument marker --% like this:
dotnet test /p:CollectCoverage=true --% /p:CoverletOutputFormat=\"opencover,lcov\"
Enabling code coverage is as simple as setting the CollectCoverage property to true
dotnet test /p:CollectCoverage=true
After the above command is run, a coverage.json file containing the results will be generated in the root directory of the test project. A summary of the results will also be displayed in the terminal.
Coverlet can generate coverage results in multiple formats, which is specified using the CoverletOutputFormat property. For example, the following command emits coverage results in the opencover format:
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
Supported Formats:
You can specify multiple output formats by separating them with a comma (,).
The output of the coverage result can be specified using the CoverletOutput property.
dotnet test /p:CollectCoverage=true /p:CoverletOutput='./result.json'
To specify a directory where all results will be written to (especially if using multiple formats), end the value with a /.
dotnet test /p:CollectCoverage=true /p:CoverletOutput='./results/'
Note: escape characters might produce some unexpected results.
| status | msbuild parameter |
|---|---|
| :heavy_check_mark: | /p:CoverletOutput="C:/GitHub/coverlet/artifacts/Reports/coverlet.core/" |
| :heavy_check_mark: | /p:CoverletOutput="C:\\GitHub\\coverlet\\artifacts\\Reports\\coverlet.core\\" |
| :heavy_check_mark: | /p:CoverletOutput="C:\GitHub\coverlet\artifacts\Reports\coverlet.core\\" |
| :x: | /p:CoverletOutput="C:\GitHub\coverlet\artifacts\Reports\coverlet.core\" |
The Coverlet MSBuild task sets the CoverletReport MSBuild item so that you can easily use the produced coverage reports. For example, using ReportGenerator to generate an html coverage report.
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
<ReportGenerator ReportFiles="@(CoverletReport)" TargetDirectory="../html-coverage-report" />
</Target>
Coverlet can output basic code coverage statistics using TeamCity service messages.
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=teamcity
The currently supported TeamCity statistics are:
| TeamCity Statistic Key | Description |
|---|---|
| CodeCoverageL | Line-level code coverage |
| CodeCoverageB | Branch-level code coverage |
| CodeCoverageM | Method-level code coverage |
| CodeCoverageAbsLTotal | The total number of lines |
| CodeCoverageAbsLCovered | The number of covered lines |
| CodeCoverageAbsBTotal | The total number of branches |
| CodeCoverageAbsBCovered | The number of covered branches |
| CodeCoverageAbsMTotal | The total number of methods |
| CodeCoverageAbsMCovered | The number of covered methods |
With Coverlet, you can combine the output of multiple coverage runs into a single result.
dotnet test /p:CollectCoverage=true /p:MergeWith='/path/to/result.json'
The value given to /p:MergeWith must be a path to Coverlet's own json result format. The results in result.json will be read, and added to the new results written to by Coverlet. .
Coverlet allows you to specify a coverage threshold below which it fails the build. This allows you to enforce a minimum coverage percent on all changes to your project.
dotnet test /p:CollectCoverage=true /p:Threshold=80
The above command will automatically fail the build if the line, branch or method coverage of any of the instrumented modules falls below 80%. You can specify what type of coverage to apply the threshold value to using the ThresholdType property. For example to apply the threshold check to only line coverage:
dotnet test /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line
You can specify multiple values for ThresholdType by separating them with commas. Valid values include line, branch and method.
You can do the same for Threshold as well.
dotnet test /p:CollectCoverage=true /p:Threshold=\"80,100,70\" /p:ThresholdType=\"line,branch,method\"
By default, Coverlet will validate the threshold value against the coverage result of each module. The /p:ThresholdStat option allows you to change this behavior and can have any of the following values:
The following command will compare the threshold value with the overall total coverage of all modules:
dotnet test /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line /p:ThresholdStat=total
You can ignore a method, an entire class or assembly from code coverage by creating and applying the ExcludeFromCodeCoverage attribute present in the System.Diagnostics.CodeAnalysis namespace.
You can also ignore additional attributes by using the ExcludeByAttribute property
Obsolete, ObsoleteAttribute, System.ObsoleteAttribute)dotnet test /p:CollectCoverage=true /p:ExcludeByAttribute="Obsolete%2cGeneratedCodeAttribute"
You can also ignore specific source files from code coverage using the ExcludeByFile property
dir1/*.cs)dotnet test /p:CollectCoverage=true /p:ExcludeByFile=\"**/dir1/class1.cs,**/dir2/*.cs,**/dir3/**/*.cs\"
Coverlet gives the ability to have fine grained control over what gets excluded using "filter expressions".
Syntax: /p:Exclude=[Assembly-Filter]Type-Filter
Wildcards
* ⇒ matches zero or more characters? ⇒ the prefixed character is optionalExamples
/p:Exclude="[*]*" ⇒ Excludes all types in all assemblies (nothing is instrumented)/p:Exclude="[coverlet.*]Coverlet.Core.Coverage" ⇒ Excludes the Coverage class in the Coverlet.Core namespace belonging to any assembly that matches coverlet.* (e.g coverlet.core)/p:Exclude="[*]Coverlet.Core.Instrumentation.*" ⇒ Excludes all types belonging to Coverlet.Core.Instrumentation namespace in any assembly/p:Exclude="[coverlet.*.tests?]*" ⇒ Excludes all types in any assembly starting with coverlet. and ending with .test or .tests (the ? makes the s optional)/p:Exclude=\"[coverlet.*]*,[*]Coverlet.Core*\" ⇒ Excludes assemblies matching coverlet.* and excludes all types belonging to the Coverlet.Core namespace in any assemblydotnet test /p:CollectCoverage=true /p:Exclude="[coverlet.*]Coverlet.Core.Coverage"
Coverlet goes a step in the other direction by also letting you explicitly set what can be included using the Include property.
Examples
/p:Include="[*]*" ⇒ Includes all types in all assemblies (everything is instrumented)/p:Include="[coverlet.*]Coverlet.Core.Coverage" ⇒ Includes the Coverage class in the Coverlet.Core namespace belonging to any assembly that matches coverlet.* (e.g coverlet.core)/p:Include="[coverlet.*.tests?]*" ⇒ Includes all types in any assembly starting with coverlet. and ending with .test or .tests (the ? makes the s optional)Both Exclude and Include properties can be used together but Exclude takes precedence. You can specify multiple filter expressions by separating them with a comma (,).
You can also include coverage of the test assembly itself by setting /p:IncludeTestAssembly to true.
Neither track nor record auto-implemented properties.
Syntax: /p:SkipAutoProps=true
Syntax: /p:InstrumentModulesWithoutLocalSources=true
Methods that do not return can be marked with attributes to cause statements after them to be excluded from coverage.
Attributes can be specified with the following syntax.
Syntax: /p:DoesNotReturnAttribute="DoesNotReturnAttribute,OtherAttribute"
To exclude or include multiple assemblies when using Powershell scripts or creating a .yaml file for an Azure DevOps build %2c should be used as a separator. Msbuild will translate this symbol to ,.
/p:Exclude="[*]*Examples?%2c[*]*Startup"
Azure DevOps builds do not require double quotes to be unescaped:
dotnet test --configuration $(buildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ /p:Exclude="[MyAppName.DebugHost]*%2c[MyAppName.WebHost]*%2c[MyAppName.App]*"
There is an issue with MSBuild on Linux that affects the ability to escape quotes while specifying multiple comma-separated values. Linux MSBuild automatically translates \ to / in properties, tasks, etc. before using them, which means if you specified /p:CoverletOutputFormat=\"json,opencover\" in an MSBuild script, it will be converted to /p:CoverletOutputFormat=/"json,opencover/" before execution. This yields an error similar to the following:
MSBUILD : error MSB1006: Property is not valid. [/home/vsts/work/1/s/default.proj]
Switch: opencover/
You'll see this if directly consuming Linux MSBuild or if using the Azure DevOps MSBuild task on a Linux agent.
The workaround is to use the .NET Core dotnet msbuild command instead of using MSBuild directly. The issue is not present in dotnet msbuild and the script will run with correctly escaped quotes.
Coverlet supports SourceLink custom debug information contained in PDBs. When you specify the /p:UseSourceLink=true property, Coverlet will generate results that contain the URL to the source files in your source control instead of local file paths.
Take a look at for further information. To generate deterministic report the parameter is:
/p:DeterministicReport=true
The heuristic coverlet uses to determine if an assembly is a third-party dependency is based on the matching of the assembly`s source documents and the corresponding source files. This parameter has three different values to control the automatic assembly exclusion.
| Parameter | Description |
|---|---|
| MissingAll | Includes the assembly if at least one document is matching. In case the ExcludeAssembliesWithoutSources parameter is not specified the default value is MissingAll. |
| MissingAny | Includes the assembly only if all documents can be matched to corresponding source files. |
| None | No assembly is excluded. |
Here is an example of how to specify the parameter:
/p:ExcludeAssembliesWithoutSources="MissingAny"
The DisableManagedInstrumentationRestore property controls whether Coverlet should restore (revert) an assembly to its original state after instrumentation. By default, this is set to false, meaning:
When set to true:
Example use case:
<PropertyGroup>
<DisableManagedInstrumentationRestore>true</DisableManagedInstrumentationRestore>
</PropertyGroup>
This setting is particularly helpful when troubleshooting instrumentation issues or when dealing with file locking problems during coverage collection.
Make sure instrumented binaries are not deployed into production.
coverlet.msbuild integrates through MSBuild targets/tasks and wraps test execution with instrumentation and report generation steps.
| Component | Dependencies | Functionality |
|---|---|---|
coverlet.msbuild |
MSBuild task APIs (Microsoft.Build.Utilities.Core), coverlet.core |
Adds targets before/after test execution, drives instrumentation, restores binaries, evaluates thresholds, writes reports |
coverlet.core |
Mono.Cecil, filtering/reporting infrastructure |
Instruments assemblies, collects hits, computes metrics, produces output formats |
flowchart LR
CLI["dotnet test"] --> MSB["MSBuild pipeline"]
MSB --> PRE["InstrumentationTask\n(before test target)"]
PRE --> CORE["coverlet.core"]
MSB --> TEST["VSTest/TestHost execution"]
TEST --> POST["CoverageResultTask\n(after test target)"]
POST --> CORE
CORE --> OUT["coverage.json/xml/etc."]
POST --> THR["Threshold evaluation\n(build pass/fail)"]
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package has no dependencies.
Showing the top 5 NuGet packages that depend on coverlet.msbuild:
| Package | Downloads |
|---|---|
|
Corvus.Testing.SpecFlow.NUnit
A metapackage that encapsulates the required dependencies when using Corvus.Testing.SpecFlow and Endjin's standard practises. Also simplifies the dependency management process when using tools like Dependabot. |
|
|
Corvus.Testing.AzureFunctions.SpecFlow.NUnit
A metapackage that encapsulates the required dependencies when using Corvus.Testing.AzureFunctions.SpecFlow and Endjin's standard practises. Also simplifies the dependency management process when using tools like Dependabot. |
|
|
Dolittle.Common.Specs
Package Description |
|
|
Klinked.Cqrs
Simple to use CQRS library. |
|
|
Klinked.Cqrs.Logging
A logging decorator for the Klinked.Cqrs library that makes it easy to add logging to all commands, events, and queries. |
Showing the top 20 popular GitHub repositories that depend on coverlet.msbuild:
| Repository | Stars |
|---|---|
|
Jackett/Jackett
API Support for your favorite torrent trackers
|
|
|
App-vNext/Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
|
|
|
chocolatey/choco
Chocolatey - the package manager for Windows
|
|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
|
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
|
|
|
elsa-workflows/elsa-core
The Workflow Engine for .NET
|
|
|
PrismLibrary/Prism
Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, Xamarin Forms, and Uno / Win UI Applications..
|
|
|
domaindrivendev/Swashbuckle.AspNetCore
Swagger tools for documenting API's built on ASP.NET Core
|
|
|
mono/SkiaSharp
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
|
|
|
dotnet/tye
Tye is a tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with minimal configuration.
|
|
|
Shane32/QRCoder
A pure C# Open Source QR Code implementation
|
|
|
dotnet/winforms
Windows Forms is a .NET UI framework for building Windows desktop applications.
|
|
|
microsoft/fluentui-blazor
Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
|
|
|
simplcommerce/SimplCommerce
A simple, cross platform, modulith ecommerce system built on .NET
|
|
|
tmenier/Flurl
Fluent URL builder and testable HTTP client for .NET
|
|
|
sshnet/SSH.NET
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
|
|
|
ivanpaulovich/clean-architecture-manga
:cyclone: Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
|
|
|
riok/mapperly
A .NET source generator for generating object mappings. No runtime reflection.
|
|
|
microsoft/kiota
OpenAPI based HTTP Client code generator
|
|
|
nuke-build/nuke
🏗 The AKEless Build System for C#/.NET
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.1 | 1,156,460 | 5/18/2026 |
| 10.0.0 | 1,536,882 | 4/17/2026 |
| 8.0.1 | 1,992,179 | 3/17/2026 |
| 8.0.0 | 1,650,720 | 2/14/2026 |
| 6.0.4 | 30,198,513 | 1/19/2025 |
| 6.0.3 | 1,880,175 | 12/30/2024 |
| 6.0.2 | 32,771,287 | 3/13/2024 |
| 6.0.1 | 2,501,575 | 2/20/2024 |
| 6.0.0 | 22,513,725 | 5/21/2023 |
| 3.2.0 | 24,282,065 | 10/29/2022 |
| 3.1.2 | 28,903,283 | 2/6/2022 |
| 3.1.1 | 686,980 | 1/30/2022 |
| 3.1.0 | 16,797,116 | 7/19/2021 |
| 3.0.3 | 13,482,390 | 2/21/2021 |
| 3.0.2 | 2,830,112 | 1/24/2021 |
| 3.0.1 | 693,245 | 1/16/2021 |
| 3.0.0 | 531,951 | 1/9/2021 |
| 2.9.0 | 21,931,518 | 5/30/2020 |
| 2.8.1 | 6,624,192 | 4/2/2020 |
| 2.8.0 | 8,211,733 | 1/3/2020 |