![]() |
VOOZH | about |
dotnet add package coverlet.collector --version 10.0.1
NuGet\Install-Package coverlet.collector -Version 10.0.1
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageVersion Include="coverlet.collector" Version="10.0.1" />Directory.Packages.props
<PackageReference Include="coverlet.collector"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>Project file
paket add coverlet.collector --version 10.0.1
#r "nuget: coverlet.collector, 10.0.1"
#:package coverlet.collector@10.0.1
#addin nuget:?package=coverlet.collector&version=10.0.1Install as a Cake Addin
#tool nuget:?package=coverlet.collector&version=10.0.1Install as a Cake Tool
Supported runtime versions:
Since version 8.0.0
As explained in quick start section, to use collectors you need to run SDK v8.0.414 (LTS) or newer and your project file must reference coverlet.collector and a minimum version of Microsoft.NET.Test.Sdk.
A sample project file looks like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TestingPlatformDotnetTestSupport>false</TestingPlatformDotnetTestSupport>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="coverlet.collector" Version="10.0.1" />
...
</ItemGroup>
...
</Project>
The reference to coverlet.collector package is included by default with xunit template test (dotnet new xunit), you only need to update the package for new versions like any other package reference.
With correct reference in place you can run coverage through default dotnet test CLI verbs:
dotnet test --collect:"XPlat Code Coverage"
or
dotnet publish
...
... -> C:\project\bin\Debug\net8.0\testdll.dll
... -> C:\project\bin\Debug\net8.0\publish\
...
dotnet vstest C:\project\bin\Debug\net8.0\publish\testdll.dll --collect:"XPlat Code Coverage"
As you can see in case of vstest verb you must publish project before.
At the end of tests you'll find the coverage file data under default VSTest platform directory TestResults
Attachments:
C:\git\coverlet\Documentation\Examples\VSTest\HelloWorld\XUnitTestProject1\TestResults\bc5e983b-d7a8-4f17-8c0a-8a8831a4a891\coverage.cobertura.xml
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 2.5451 Seconds
You can change the output directory using the standard dotnet test switch --results-directory
By design VSTest platform will create your file under a random named folder(guid string) so if you need stable path to load file to some gui report system(i.e. coveralls, codecov, reportgenerator etc..) that doesn't support glob patterns or hierarchical search, you'll need to manually move resulting file to a predictable folder
⚠️At the moment VSTest integration doesn't support all features of msbuild and .NET tool, for instance show result on console, report merging and threshold validation. We're working to fill the gaps.
Some alternative solutions to merge coverage files
use dotnet-coverage tool and merge multiple coverage files
dotnet-coverage merge artifacts/coverage/**/coverage.cobertura.xml -f cobertura -o artifacts/coverage/coverage.xml*
use dotnet-reportgenerator-globaltool to create a HTML report and a merged coverage file
reportgenerator -reports:"**/*.cobertura.xml" -targetdir:"artifacts\reports.cobertura" -reporttypes:"HtmlInline_AzurePipelines_Dark;Cobertura"
Without specifying a runsettings file and calling coverlet by just the name of the collector, the result of the generated coverage output is by default in cobertura format.
dotnet test --collect:"XPlat Code Coverage"
The output format of the coverage report can also be changed without a runsettings file by specifying it in a parameter. The supported formats are lcov, opencover, cobertura, teamcity, json (default coverlet proprietary format).
dotnet test --collect:"XPlat Code Coverage;Format=json"
It is even possible to specify the coverage output in multiple formats.
dotnet test --collect:"XPlat Code Coverage;Format=json,lcov,cobertura"
These are a list of options that are supported by coverlet. These can be specified as datacollector configurations in the runsettings.
| Option | Summary |
|---|---|
| Format | Coverage output format. These are either cobertura, json, lcov, opencover or teamcity as well as combinations of these formats. <br>Default is cobertura. |
| Exclude | Exclude from code coverage analyzing using filter expressions. <br>Default is [coverlet.*]*,[xunit.*]*,[NUnit3.*]*,[Microsoft.Testing.*]*,[Microsoft.Testplatform.*]*,[Microsoft.VisualStudio.TestPlatform.*]*. User-supplied filters are appended to these defaults. |
| ExcludeByAttribute | Exclude a method, an entire class or assembly from code coverage decorated by an attribute. <br>Default is no additional attributes, but ExcludeFromCoverageAttribute and ExcludeFromCodeCoverageAttribute are always excluded. |
| ExcludeByFile | Ignore specific source files from code coverage.<br>Default is none. |
| Include | Explicitly set what to include in code coverage analysis using filter expressions.<br>Default is no include filters (all coverable modules except excluded ones). |
| IncludeDirectory | Explicitly set which directories to include in code coverage analysis.<br>Default is none. |
| SingleHit | Specifies whether to limit code coverage hit reporting to a single hit for each location. <br>Default is false. |
| UseSourceLink | Specifies whether to use SourceLink URIs in place of file system paths.<br>Default is false. |
| IncludeTestAssembly | Include coverage of the test assembly.<br>Default is false. |
| SkipAutoProps | Neither track nor record auto-implemented properties.<br>Default is false. |
| DoesNotReturnAttribute | Methods marked with these attributes are known not to return, statements following them will be excluded from coverage.<br>Default is none. |
| DeterministicReport | Generates deterministic report in context of deterministic build. Take a look at for further information.<br>Default is false. |
| ExcludeAssembliesWithoutSources | Specifies whether to exclude assemblies without source. Options are either MissingAll, MissingAny or None. <br>Default is MissingAll. |
How to specify these options via runsettings?
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>json,cobertura,lcov,teamcity,opencover</Format>
<Exclude>[coverlet.*.tests?]*,[*]Coverlet.Core*</Exclude>
<Include>[coverlet.*]*,[*]Coverlet.Core*</Include>
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
<ExcludeByFile>**/dir1/class1.cs,**/dir2/*.cs,**/dir3/**/*.cs,</ExcludeByFile>
<IncludeDirectory>../dir1/,../dir2/,</IncludeDirectory>
<SingleHit>false</SingleHit>
<UseSourceLink>true</UseSourceLink>
<IncludeTestAssembly>true</IncludeTestAssembly>
<SkipAutoProps>true</SkipAutoProps>
<DeterministicReport>false</DeterministicReport>
<ExcludeAssembliesWithoutSources>MissingAll,MissingAny,None</ExcludeAssembliesWithoutSources>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
Filtering details are present on .
This runsettings file can easily be provided using command line option as given :
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettingsdotnet vstest C:\project\bin\Debug\netcoreapp3.0\publish\testdll.dll --collect:"XPlat Code Coverage" --settings coverlet.runsettingsTake a look at our sample.
You can avoid passing a runsettings file to dotnet test driver by using the xml flat syntax in the command line.
For instance if you want to set the Format element as a runsettings option you can use this syntax:
dotnet test --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover
Take a look here for further information:https://github.com/microsoft/vstest/blob/main/docs/RunSettingsArguments.md
Coverlet integration is implemented with the help of datacollectors.
When we specify --collect:"XPlat Code Coverage" VSTest platform tries to load coverlet collectors inside coverlet.collector.dll
Out-of-proc Datacollector: The outproc collector run in a separate process(datacollector.exe/datacollector.dll) than the process in which tests are being executed(testhost*.exe/testhost.dll). This datacollector is responsible for calling into Coverlet APIs for instrumenting dlls, collecting coverage results and sending the coverage output file back to test platform.
In-proc Datacollector: The in-proc collector is loaded in the testhost process executing the tests. This collector will be needed to remove the dependency on the process exit handler to flush the hit files and avoid to hit this
coverlet.collector uses a controller-style integration where VSTest remains the orchestrator and Coverlet hooks into collector lifecycle callbacks.
| Component | Dependencies | Functionality |
|---|---|---|
coverlet.collector |
VSTest Data Collector APIs (Microsoft.TestPlatform.ObjectModel), coverlet.core |
Coordinates pre/post test collection, instruments targets, collects hit files, publishes coverage as test attachments |
coverlet.core |
Mono.Cecil, filtering/reporting infrastructure |
IL instrumentation, hit tracking, coverage aggregation, report generation |
flowchart LR
VS["vstest.console / dotnet test"] --> OOP["Out-of-proc Data Collector\ncoverlet.collector"]
VS --> TH["testhost"]
TH --> IP["In-proc Data Collector\ncoverlet.collector"]
OOP --> CORE["coverlet.core"]
IP --> CORE
CORE --> REP["coverage reports"]
OOP --> ATT["VSTest attachments\nTestResults/<guid>"]
TestResults/<guid> (platform-controlled, non-deterministic folder names).Microsoft.NET.Test.Sdk and collector setup.For a comprehensive list of known issues check the detailed documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
This package has no dependencies.
Showing the top 5 NuGet packages that depend on coverlet.collector:
| Package | Downloads |
|---|---|
|
Reo.Core.IntegrationTesting
Package Description |
|
|
gdUnit4.test.adapter
GdUnit4 Test Adapter is the test adapter to run GdUnit4 tests in C#. |
|
|
Kasp.Test
some tools for fast developing back-end. |
|
|
Uno.Extensions.Reactive.Testing
Extensions to accelerate your application development with Uno Platform, UWP and WinUI |
|
|
Coffee.NetCore
Package Description |
Showing the top 20 popular GitHub repositories that depend on coverlet.collector:
| Repository | Stars |
|---|---|
|
jellyfin/jellyfin
The Free Software Media System - Server Backend & API
|
|
|
DevToys-app/DevToys
A Swiss Army knife for developers.
|
|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
NickeManarin/ScreenToGif
🎬 ScreenToGif allows you to record a selected area of your screen, edit and save it as a gif or video.
|
|
|
Devolutions/UniGetUI
UniGetUI: The Graphical Interface for your package managers. Could be terribly described as a package manager manager to manage your package managers
|
|
|
dotnet/maui
.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
|
|
|
jasontaylordev/CleanArchitecture
Clean Architecture Solution Template for ASP.NET Core
|
|
|
bitwarden/server
Bitwarden infrastructure/backend (API, database, Docker, etc).
|
|
|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 10
|
|
|
dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
|
|
|
netchx/netch
A simple proxy client
|
|
|
duplicati/duplicati
Store securely encrypted backups in the cloud!
|
|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
QuestPDF/QuestPDF
QuestPDF is a modern library for PDF document generation. Its fluent C# API lets you design complex layouts with clean, readable code. Create documents using a flexible, component-based approach.
|
|
|
winsw/winsw
A wrapper executable that can run any executable as a Windows service, in a permissive license.
|
|
|
Sonarr/Sonarr
Smart PVR for newsgroup and bittorrent users.
|
|
|
babalae/better-genshin-impact
📦BetterGI · 更好的原神 - 自动拾取 | 自动剧情 | 全自动钓鱼(AI) | 全自动七圣召唤 | 自动伐木 | 自动刷本 | 自动采集/挖矿/锄地 | 一条龙 | 全连音游 | 自动烹饪 - UI Automation Testing Tools For Genshin Impact
|
|
|
Radarr/Radarr
Movie organizer/manager for usenet and torrent users.
|
|
|
SubtitleEdit/subtitleedit
the subtitle editor :)
|
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.1 | 4,926,271 | 5/18/2026 |
| 10.0.0 | 6,863,874 | 4/17/2026 |
| 8.0.1 | 8,702,501 | 3/17/2026 |
| 8.0.0 | 7,782,920 | 2/14/2026 |
| 6.0.4 | 135,015,622 | 1/19/2025 |
| 6.0.3 | 7,697,585 | 12/30/2024 |
| 6.0.2 | 128,060,105 | 3/13/2024 |
| 6.0.1 | 8,476,673 | 2/20/2024 |
| 6.0.0 | 132,206,651 | 5/21/2023 |
| 3.2.0 | 92,319,782 | 10/29/2022 |
| 3.1.2 | 136,891,240 | 2/6/2022 |
| 3.1.1 | 1,651,374 | 1/30/2022 |
| 3.1.0 | 66,185,565 | 7/19/2021 |
| 3.0.3 | 19,102,735 | 2/21/2021 |
| 3.0.2 | 31,147,261 | 1/24/2021 |
| 3.0.1 | 1,123,436 | 1/16/2021 |
| 3.0.0 | 810,589 | 1/9/2021 |
| 1.3.0 | 51,633,797 | 5/30/2020 |
| 1.2.1 | 6,603,212 | 4/2/2020 |
| 1.2.0 | 49,893,502 | 1/3/2020 |