Cake.Coverlet 4.0.1

dotnet add package Cake.Coverlet --version 4.0.1                
NuGet\Install-Package Cake.Coverlet -Version 4.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cake.Coverlet" Version="4.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cake.Coverlet --version 4.0.1                
#r "nuget: Cake.Coverlet, 4.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Cake.Coverlet&version=4.0.1                

Cake.Coverlet

Build status NuGet version

Usage

In order to use the addin please make sure you've included Coverlet in the project you wish to cover and add the following to your cake build file

#addin nuget:?package=Cake.Coverlet

You can also install coverlet as a global tool on your machine or with the Cake.DotNetTool.Module and run the command separately from MSBuild.

Note: Works with Coverlet 2.1.1 and up

Then use one of the following snippets

Task("Test")
    .IsDependentOn("Build")
    .Does<MyBuildData>((data) =>
{
    var testSettings = new DotNetTestSettings {
    };

    var coverletSettings = new CoverletSettings {
        CollectCoverage = true,
        CoverletOutputFormat = CoverletOutputFormat.opencover,
        CoverletOutputDirectory = Directory(@".\coverage-results\"),
        CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"
    };

    DotNetTest("./test/My.Project.Tests/My.Project.Tests.csproj", testSetting, coverletSettings);
}

Or for when installed as a tool:

Task("Test")
    .IsDependentOn("Build")
    .Does<MyBuildData>((data) =>
{
    var coverletSettings = new CoverletSettings {
        CollectCoverage = true,
        CoverletOutputFormat = CoverletOutputFormat.opencover,
        CoverletOutputDirectory = Directory(@".\coverage-results\"),
        CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"
    };

    // I want to specify the specific dll file and the project exactly.
    Coverlet(
        "./test/My.Project.Tests/bin/Debug/net46/My.Project.Tests.dll", 
        "./test/My.Project.Tests/My.Project.Tests.csproj", 
        coverletSettings);

    // I want to specify just the project file and the dll can be
    // inferred from the name of the project file.
    Coverlet(
        "./test/My.Project.Tests/My.Project.Tests.csproj", 
        coverletSettings);

    // I want to specify just the project directory, we will discover
    // any proj file in the directory (take the first) and infer the 
    // name from the found project.
    Coverlet(
        "./test/My.Project.Tests",
        coverletSettings);
}

There is an additional api exposed for transforming the output name of the coverage file at the time of calling dotnet test. This transform function follows the form Func<string, string> being passed the CoverletOutputName and the return is used for the filename.

Task("Test")
    .IsDependentOn("Build")
    .Does<MyBuildData>((data) =>
{
    var testSettings = new DotNetTestSettings {
    };

    var coverletSettings = new CoverletSettings {
        CollectCoverage = true,
        CoverletOutputFormat = CoverletOutputFormat.opencover,
        CoverletOutputDirectory = Directory(@".\coverage-results\"),
        CoverletOutputName = $"results"
        OutputNameTransformer = (fileName, directory) => $@"{directory}\{fileName}-HelloWorld"
    };

    DotNetTest("./test/Stubble.Core.Tests/Stubble.Core.Tests.csproj", testSetting, coverletSettings);
}

We expose a default transformer for the standard practice of appending the current datetime to the file as WithDateTimeTransformer()

If you wish to only change the directory that the output is written to then set the CoverletOutputDirectory and the filename handling will be done by coverlet as usual.

Setting more than one output format

You can support multiple coverlet formats by providing them like this:

var coverletSettings = new CoverletSettings {
        CollectCoverage = true,
        CoverletOutputFormat = CoverletOutputFormat.opencover | CoverletOutputFormat.cobertura,
        CoverletOutputDirectory = Directory(@".\coverage-results\"),
        CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"
    };

Or by using the method on the settings class like this:

var coverletSettings = new CoverletSettings {
        CollectCoverage = true,
        CoverletOutputFormat = CoverletOutputFormat.opencover,
        CoverletOutputDirectory = Directory(@".\coverage-results\"),
        CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"
    }.WithFormat(CoverletOutputFormat.cobertura);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Cake.Coverlet:

Package Downloads
Cake.Tasks.DotNetCore

Cake .NET Core tasks

Devocean.Tests

Devocean.Tests is a set of base classes and helpers inteded to support implementing integration and unit tests on projects based on Devocean.Core

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Cake.Coverlet:

Repository Stars
GitTools/GitVersion
From git log to SemVer in no time
octokit/octokit.net
A GitHub API client library for .NET
charlessolar/Aggregates.NET
.NET event sourced domain driven design model via NServiceBus and GetEventStore
Version Downloads Last updated
4.0.1 40,125 3/9/2024
3.0.4 245,266 12/7/2022
3.0.3 351 12/7/2022
3.0.2 66,698 11/17/2022
2.5.4 760,366 2/15/2021
2.5.1 199,255 9/3/2020
2.4.2 214,368 1/30/2020
2.3.4 706,406 6/2/2019
2.2.1 221,983 1/13/2019
2.1.2 51,191 12/11/2018
2.0.1 1,092 12/3/2018
1.3.2 17,859 9/26/2018
1.3.1 7,738 9/4/2018
1.2.1 1,005 9/1/2018
1.1.4 3,087 7/23/2018
1.1.3 981 7/20/2018
1.1.2 1,035 7/18/2018
1.0.4 5,940 7/2/2018
1.0.3 985 6/27/2018