Project assembly attribute is ignored

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C#

When setting

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

in a project file, which is the recommended way by Microsoft to exclude entire assemblies from coverage, the code coverage tools will not collect any coverage for files in that project.
I.e the files will be missing in the coverage report sent to Sonar for analysis.
Since Sonar uses

“executable lines of code” which is used in addition to the coverage info to track lines covered/uncovered. All files excluded does not have any coverage info BUT using the executable lines of code will appear as un-covered on SonarQube.

this will lead to falsely report lower coverage than is expected. Only way to “override” coverage at this point is to set the attribute [ExcludeFromCodeCoverage] on classes/methods.

It is in my opinion a bug that should be fixed by Sonar. If a project has this assembly attribute all the underlying files should be excluded from code coverage analysis.

Hi there, @Michael_Sendow

You are right that this attribute is not supported at the assembly level, and it should be.
I have recorded this in our backlog so we can look at it when we work on test coverage.

Thank you for reporting this!
Denis.

That is great news!