Should SonarCloud respect exclude when using .NET core test .runsettings file?

We are using:

  • Azure DevOps extension v1.10
  • SonarCloud (paid plan/private projects)
  • yaml build pipelines
  • C#
  • .NET core
  • xUnit tests

We would like to exclude source code in a certain folder from code coverage, and understand that we can do this; either using the SonarCloud UI or specifying extraProperties to the prepare task in yaml, similar to the following:

  • task: SonarCloudPrepare@1
    SonarCloud: …
    organization: …
    scannerMode: ‘MSBuild’
    projectKey: …
    projectName: …
    extraProperties: |

However, we would like to know if we can get this to work using a “.runsettings” file instead. See also:

We have a “.runsettings” file and refer to it when running the “dotnet test” command. On the build report we get the expected “.coverage” file and can see the source files in the specified folder was excluded. The benefit of this is that developers can download the “.coverage” file and open it directly in Visual Studio to get the details about coverage, close to their code.

But in SonarCloud the files are not excluded. Is this the expected behavior, or is it possible to get SonarCloud to “respect” the “.runsettings” file? I guess it should not actually respect the “.runsettings” file, but maybe it could look at the “.coverage” file and only “include” files that are part of that and have any coverage calculated.

The benefit, as I see it (but I might overlook something), would be that we only configure this in the “.runsettings” file and hence the “code coverage” report on the build, and what you would see in the SonarCloud UI, would be perfectly aligned.

Best regards,

Hi @xdastendk,

runsettings files only change the content of the coverage file itself like you said, we don’t do anything with it currently.

So the only way to achieve what you want is by specified relevant exclusions patterns.

If you want to suggest a new feature, you can post it on the github repo of the Scanner :


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.