C# – Why we should build with the highest warning level in .NET

cmsbuildnet

I heard that we have to build with the highhest warning level.

Is it true? why?

And how to change default .NET warning level?

Best Answer

You don't have to, but it is a good idea to build with the highest warning level. Why? Warnings are potential problems with your code - things you might have done wrong, badly or in a way that is likely to cause problems.

Turning on the warnings at the highest level will highlight these problems, allowing you to fix them early, rather than let them become potential bugs at a later date. Plus, you'll learn good programming practice as you compile - improving your coding as you go.

Edit: In Visual Studio 2010, you can change the warning level for a project by right-clicking on it, going to its properties page and then setting warning level to 4 on its Build tab. If you also tick 'Warnings as errors', any warnings will break your build - so you'll have to fix them.