Romanx / Cake.Coverlet

Coverlet extensions for Cake Build
MIT License
40 stars 15 forks source link

The type or namespace name 'CoverletSettings' could not be found. #18

Closed dcjulian29 closed 5 years ago

dcjulian29 commented 5 years ago

Preparing to run build script... Running build script... Analyzing build script... Processing build script... Installing tools... Compiling build script... Error: C:/code/toolkit/build.cake(161,17): error CS0246: The type or namespace name 'CoverletSettings' could not be found (are you missing a using directive or an assembly reference?)

The Cake.Build Script starts:

tool "nuget:?package=xunit.runner.console"

tool "nuget:?package=OpenCover"

tool "nuget:?package=ReportGenerator"

tool "nuget:?package=Cake.Coverlet"

And the tasks that uses it:

Task("Coverage2") .IsDependentOn("Compile") .Does(() => { CreateDirectory(buildDirectory + "\coverage");

    Coverlet(
        buildDirectory + "\\output\\UnitTest.dll",
        baseDirectory + "\\UnitTests\\UnitTests.csproj",
        new CoverletSettings {
            CollectCoverage = true,
            CoverletOutputFormat = CoverletOutputFormat.opencover,
            CoverletOutputDirectory = Directory(buildDirectory + "\\coverage"),
            CoverletOutputName = "coverage.xml"
        });

    ReportGenerator(buildDirectory + "\\coverage\\coverage.xml", buildDirectory + "\\coverage");
});

Not sure what I'm doing wrong...

Romanx commented 5 years ago

If possible could you provider some more information or even a reproduction case that I can use? Operating system, coverlet and cake version would be a useful starting point.

Thanks,

dcjulian29 commented 5 years ago

OS: Windows 10 (1809 OS Build 17763.195) Cake: 0.19.4 Coverlet: 2.1.2

The entire project is at: https://github.com/dcjulian29/toolkit/tree/feature/CoverletCoverage

I run the build process by typing: ./build.ps1 --Target CodeCoverage2

dcjulian29 commented 5 years ago

I figured it out. If Cake.Coverlet is added via the #tool directive, then the error above occurs, if using the #addin directive, it doesn't. I got confused when I saw "when installed as tool" which I now realize means installing it via "dotnet install" which is what I do not want to do. Also the project I'm trying to collect code coverage on is a mix of .Net Framework and .Net Core code so a solution that only works with one will not work for me. Thanks.

Romanx commented 5 years ago

Hey @dcjulian29,

Thanks for commenting here for others to see the solution. I agree that can get very confusing and i've run into it myself.

If i'm right you should be able to use coverlet via dotnet tool on dotnet framework code without an issue. The only requirement is that the host running coverlet can run the dotnet tool.

Thanks!

dcjulian29 commented 5 years ago

My biggest problem currently is that my Unit Test project is .Net 4.7 Framework that include a mix of .Net Core and .Net 4.7 libraries... Unfortunately, it took me a long time to figure out that the reason the code coverage tool wasn't identifying the .Net Core classes/methods was that by default, .Net Core doesn't produce "Full" PDB files by default. Changing the .Net Core projects to produce full PDB files solve the original problem regarding code coverage of the mixed framework solutions...