Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify ExcludeFromCodeCoverage at assembly level for dot net framework class library?

I want to exclude a test project from code coverage, I do see equivalent of same in .Net core 3.1 is adding below line of code in csproj file

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

How to specify same thing in dot net framework 4.8 csproj class library file?

like image 434
Roshan Avatar asked May 08 '26 20:05

Roshan


1 Answers

The <AssemblyAttribute> item only works in SDK-based projects. So if you create an SDK-based .NET Framework csproj, it will work (do note this might clash with any existing AssemlyInfo.cs if one exists). e.g.:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage" />
  </ItemGroup>
</Project>

Otherwise, I worked on a similar situation a while back and created a drop-in replacement for the assembly info generation logic for non-SDK csproj, see https://github.com/dasMulli/AssemblyInfoGenerationSdk for that (do log issues if it doesn't work). Do note that you may need to disable some generation of e.g. Version attributes similar to SDK-style projects so it doesn't clas with existing AssemblyInfo.cs files.

like image 79
Martin Ullrich Avatar answered May 11 '26 11:05

Martin Ullrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!