I am compiling an .Netcore application using Azure DevOps build pipeline. In the .Netcore test build task, I have passed the below arguments for collecting the code coverage results:
--configuration $(BuildConfiguration) --collect"XPlat Code Coverage"
For publishing Code Coverage results, I have used "Publish Code Coverage Results" build task using "Cobertura" tool.
The code coverage analyzes all solution assemblies that are loaded during unit tests. But I want to exclude test code from code coverage results and only include application code through the Azure DevOps build pipeline.
For that I have referred this documentation. Based on this documentation you need to add the “ExcludeFromCodeCoverageAttribute” attribute to each test class. But I want do it through the Azure DevOps build pipeline.
I was in your same situation months ago. But instead of Coverlet I'm using the native MS Code Coverage tool in this way:
This works well but there is your same problem. I resolved using filtering with ReportGenerator task:
It works well. For other questions, see my GitHub answer here