Integrate SonarQube with your AI agent, scan for secrets and dependency risks, and explore and manage issues—all from the command line.
Start using SonarQube CLI
I have an NUnit test project targeting .NET 7 using Coverlet for calculating the code coverage. I want to exclude the class Program (see here) from coverage calculation. Since I’m using minimal API, I had to use the following tweak:
[ExcludeFromCodeCoverage]
public partial class Program
{
}
This works fine when using dotCover in my IDE.
However, when calculating the coverage for SonarCloud via dotnet-coverage (as described here), the class is not excluded anymore.
It looks like the file isn’t represented at all in the coverage report, (there is no Program.cs represented in a <source_files> block) which means that SonarQube assumes coverage is 0 for that file.
In this case, you would need to set coverage exclusions by narrowing the focus.