3

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?

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

1

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.

kthy
  • 827
  • 10
  • 27