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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With