coverlet: Assembly marked as ExcludeFromCodeCoverage is not excluded

Description When an assembly decorated with ExcludeFromCodeCoverage attribute, it is not excluded from coverage report.

Repro steps Example code:

using System.Diagnostics.CodeAnalysis;
using System

[assembly: ExcludeFromCodeCoverage]
namespace ExampleNs
{
    public class ExampleClass:
    {
        public Guid Id { get; set; }
    }
}

Expected behavior Assembly is excluded from the coverage report

Actual behavior Assembly is included in the coverage report

Known workarounds Passing the assembly with --exclude “[Assembly]*” works

Related information Cross platform .NET Core code coverage tool version 1.3.0.0 Visual Studio Version: Visual Studio Professional 2017 Microsoft ® Test Execution Command Line Tool Version 15.9.0 Test project build with .Net Core 2.1

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15

Most upvoted comments

@tonerdo I re-opened this issue, I think we should support this behaviour because it’s a default for most coverage tools. If you don’t agree please let me know. @petli what do you think?

@tonerdo it’s a pity. I want to define all my exclusions in code, so that different code coverage tools can reuse them.

exclusion attributes don’t work on assemblies by design

@sshukurov by this I mean that Coverlet doesn’t check for attributes on assemblies. It does however, have an exclude option that supports specifying assemblies

This should be supported. May this issue be reopened? (And eventually handled… this should not be too complicated to implement.)

When you look at the attribute (link below) it specifies it is valid on assemblies, yet it doesn’t change the output. Is this an error in documentation?

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=net-5.0

I still see the same issue in VS 2019 with collector v.1.3.0. Can someone help?

guys, does it work already? if yes, from which version?