TreatWarningsAsErrors in Directory.Build.props

Current situation: 10 csproj files mention <TreatWarningsAsErrors>true</TreatWarningsAsErrors> .
Cf. Configuration of WarningsAsErrors for .NET build SonarCloud overrides this setting to enable the warning collection :white_check_mark:

I want to extract common MSBuild properties to a Directory.Build.props file, one of those properties is TreatWarningsAsErrors.

Now when I run the analysis SonarCloud is no longer able to overrule this setting? And it fails my analysis step in CI. :-1:

Any suggestions?

  • ALM used : GitHub
  • CI system used : TeamCity
  • Scanner command used when applicable : SonarCloud
  • Languages of the repository: .NET C#

Hi @janv8000,

I’m not sure I understand what you’re trying to achieve. What’s the point of having <TreatWarningsAsErrors>true</TreatWarningsAsErrors> when you want it to be overridden by SonarCloud analysis?

Also please share what version of Scanner for .NET, or Azure DevOps extensioni are you using.

I leave TreatWarningsAsErrors on so regular C#/.NET warnings have to be fixed in Visual Studio otherwise the build does not complete.

SonarCloud invents/injects other warnings during analysis and specifically disables TreatWarningsAsErrors so as not to fail the build => OK in continuous integration .

SonarCloud is the cloud-hosted version
TeamCity plugin:
Sonar runner Allows configuring and running SonarQube analysis on the TeamCity server, version 2020.1-11
TeamCity tool: SonarScanner for MSBuild v


Just to clarify: are you asking whether setting <TreatWarningsAsErrors>true</TreatWarningsAsErrors> will cause a problem with the CI analysis, or stating that it is a problem?

The SonarScanner for .NET sets the property dynamically during the build, so it should override the static value set in the project. Is this not the behaviour you are seeing?

Nevermind this topic, I was using the MSBuildTreatWarningsAsErrors property

Maybe this property should also be overriden in OverrideRoslynCodeAnalysisProperties in SonarQube.Integration.targets .

Thanks @janv8000.

FYI the scanner does correctly override the TreatWarningsAsErrors MSBuild property, but not the MSBuildTreatWarningsAsErrors property.

We’ll create a ticket to look at it.

Update: ticket is S4Net #1603

1 Like

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