How mark a csproj to be ignored on collect code coverage?
See original GitHub issueIs 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:
- Created 3 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
<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
I’m going to close this as solved.
Feel free to reopen if needed.