question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How mark a csproj to be ignored on collect code coverage?

See original GitHub issue

Is there a way to mark in csproj to be ignored in the collection?

Maybe with some csproj entry like

     <PropertyGroup>
         <ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage>
     </PropertyGroup>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tonyhallettcommented, Dec 12, 2020

Yes.

The correct method is to apply the ExcludeFromCodeCoverage attribute to the assembly, although unfortunately this will not work for .NET Framework as the AttributeUsage does not include Assembly.

The documentation isn’t clear that this is possible for all 3 drivers, it only mentions it for the global tool and MSBuild integration

https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/GlobalTool.md#excluding-from-coverage https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#excluding-from-coverage

You can ignore a method an entire class or assembly from code coverage by creating and applying the ExcludeFromCodeCoverage attribute present in the System.Diagnostics.CodeAnalysis namespace.

<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage"></AssemblyAttribute>

If you are interested all 3 drivers quickly call into https://github.com/coverlet-coverage/coverlet/blob/b63ab2adf7970fe074232622cb58ae1928aa7717/src/coverlet.core/Coverage.cs#L104 here you can see the exclude and include filters being used to determine if the module should be instrumented.

Although the code that checks for the ExcludeFromCodeCoverage attribute on the assembly is in the Instrumenter https://github.com/coverlet-coverage/coverlet/blob/b63ab2adf7970fe074232622cb58ae1928aa7717/src/coverlet.core/Instrumentation/Instrumenter.cs#L233

I think that the exclusion code for the assembly attribute should change to be a name match rather than a full name match as per type and method matching - https://github.com/coverlet-coverage/coverlet/blob/5cb26b13e9133c785488234b19f59fc68d8a1eef/src/coverlet.core/Instrumentation/Instrumenter.cs#L76

This way a .Net Framework project can opt out of code coverage in the same manner. @MarcoRossignoli what do you think ? The assembly attribute commit https://github.com/coverlet-coverage/coverlet/commit/83c47b8dd4abd820f573aa4b4feff36c638eedcc

0reactions
MarcoRossignolicommented, Dec 20, 2020

I’m going to close this as solved.

Feel free to reopen if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing Code Coverage Analysis - Visual Studio
You can include or exclude assemblies or specific types and members from code coverage analysis. If the Include section is empty or omitted, ......
Read more >
How to exclude code from code coverage
The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class ...
Read more >
Exclude (conditional) linked source files from code coverage
I managed to get it work by adding a CodeCoverage.runsettings file as a solution item: <?xml version="1.0" encoding="utf-8"?> <!
Read more >
Ignore parts of the code - ReSharper
cs) under Elements to skip on the Code Inspection | Ignored Code page of ReSharper options ( Alt+R, O ). To ignore the...
Read more >
C# Code Coverage Ignoring Certain Projects - SonarQube
Hi,. We're using SonarCloud and are using the test code coverage tools. For some reason a couple of projects do not report code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found