Custom attributes in .runsettings not ignored on SonarCloud

We have specified in our .runsettings a custom attribute to indicate which code should be ignored in Code Coverage reports on SonarCloud.


When excluding code using [ApiController] it still gets flagged on SonarCloud for failing code coverage. However when using [ExcludeFromCodeCoverage] that is setup in the exact same way it correctly exclude it from the analysis.

The [ApiController] gets correctly ignored with the Visual Studio and Azure Pipelines reports.

Would appreciate any assistance.

Information about our setup:

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps (YAML), and OpenCover for Code Coverage
  • Languages of the repository - JavaScript, Vue, C#
  • SonarCloud project is not public

hello @Carike

Thanks for opening this issue.

We have a ticket for this: Code Coverage: exclusions in .runsettings file are ignored. No ETA for it yet.

As an alternative, please try telling OpenCover to exclude from code coverage based on this attribute. See this comment on how to do it. TL;DR:

If you add the parameter -excludebyattribute:*.ExcludeFromCodeCoverageAttribute to the opencover.exe command line in the repro build script you should find that the expected classes are excluded from the coverage report.

1 Like