mark
mark

Reputation: 62804

How to run coverlet on .NET projects not using the Sdk style projects?

I would like to try coverlet, but the only examples I could find talk about running it through dotnet.exe. My problem is that our projects do not use the Sdk style, they are old .NET projects targeting .NET 4.7.2

How can I run coverlet with them?

Upvotes: 3

Views: 1303

Answers (1)

kthy
kthy

Reputation: 896

I'm on VS2017 building against .NET Framework 4.6.1 and have .NET Core SDK v2.1.511 installed. I haven't figured out a way to run coverlet without using dotnet, but this works for me:

Run Install-Package coverlet.msbuild in the package manager console for all your test projects (only).

Then add something like the following task to your build script:

Task("Coverage")
    .IsDependentOn("Build")
    .Does(() =>
{
    StartProcess("dotnet" , new ProcessSettings {
        Arguments = new ProcessArgumentBuilder()
            .Append("test")
            .Append("/p:CollectCoverage=true")
            .Append("/p:CoverletOutputFormat=opencover")
    });
});

By adding OpenCoverReportsPath = "**/*.opencover.xml" to my SonarBeginSettings I now get coverage reports in SonarQube.

Upvotes: 1

Related Questions