How to treat all warnings as compile errors in .NET

Warnings are too easy to ignore.

Consider treating all warnings as errors by setting the TreatWarningsAsErrors property to true in your project files(s) or your directory level Directory.Build.props file(s).

I always turn this on for all greenfield projects.

For existing brownfield projects it can be a little painful sometimes to turn it on as depending on the code base there could be a lot of compile errors flagged.

It’s worth it to fix these issues in the long run but as a step in the right direction remember you can set this on a project by project basis and you can exclude certain exceptions via the WarningsNotAsErrors property shown above if you need to.

Do you treat any warnings as errors?

Leave a Reply

Your email address will not be published. Required fields are marked *