Build pipeline is reporting warnings for files that are configured as exclusions

I have exclusions configured in a sonarcloud project, and an Azure Devops CI pipeline that looks like this
… which I believe is the correct arrangement of tasks WRT sonar.

One of the exclusions for analysis is **\*.Tests\**\*.cs (to avoid analyzing unit tests). When I submit a PR and the CI build is triggered, dozens of S**** (sonar analysis) warnings are being emitted during the MsBuild step for files that match the exclusion pattern.

When the pipeline is complete and results uploaded to sonar, there are no issues that correspond to those build warnings in the sonarcloud UI. This tells me that the configuration is correct and is matching and excluding files that I intend it to.

Why is the msbuild task not also doing the same?

Hey Andrew.

Exclusions are only taken into account during the Run Code Analysis step, not during the build when the Roslyn analyzers are run. Hopefully we’ll improve on that this year.

Is there any way to avoid generating all these build warnings?

Only if you exclude the whole project from analysis (for example, in the test project’s .csproj file)

means I cant have rules like this one.

I thought your goal was to not analyze unit tests? :smiley:

No, the goal was to have the S warnings not show up for files that are marked as exclusions. I could have picked an exclusion for **\Program.cs, in neither case would I want to exclude the whole project.

Unfortunately, for now, you won’t be able to suppress the warnings unless you exclude the unit test project entirely or disable the rule(s) in your Quality Profile. Hopefully this improves in the future.


Did nobody notice dozens of incorrect warnings being emitted from a build?

EDIT: @Colin_SonarSource - if we changed this property on the “Prepare Analysis” task to “Use standalone scanner” instead of integrate with MSBuild, would we get the same quality results reported but without the build warnings?

Hello @StingyJack

If you want to analyze .NET code (C# or VB .NET), you need to integrate with MSBuild.