dotnet 7 exclude a dll from coverage report

If you want to exclude a dll or a project to be excluded from the code coverage report of dotnet test command then you need to add the following code in the project file of your project which you want to be excluded:

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

dotnet test command will not exclude that dll now from the code coverage results.