6

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

Is it true? why?

And how to change default .NET warning level?

Martijn Verburg
  • 22,006
  • 1
  • 49
  • 81
  • 1
    The question is also completely subjective. If you think you need all the warnings then have them on, otherwise don't. You could go further and install ReSharper - that will give you hundreds more warnings if warnings are what you like. –  Jun 06 '11 at 08:48
  • @James, I'm not looking for warnings, I heard it from a real expert and he recommend me to resolve them as much as possible, but it seems wierd to me so that I shared it here with you. –  Jun 06 '11 at 08:50
  • Personally, I enable all warnings AND set "Treat warnings as errors" in VS. And I have Resharper too. Most of the time, warnings are actually errors or sloppy code that needs to be fixed. This setup doesn't allow me to skip fixing. – Nevermind Jun 06 '11 at 09:33
  • 1
    It also worth mentioning the VS static analysis and code contracts - it will add some more warnings. – SK-logic Jun 06 '11 at 10:00
  • 1
    For me this is true for any language, not just about .NET. Configure the system to show all warnings, and you choose to treat or ignore them. But at least you'll see them. – Carlos Campderrós Jun 06 '11 at 13:18

2 Answers2

14

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.

Jackson Pope
  • 375
  • 1
  • 10
2

It helps you ensure you check all of the warnings.

These warnings may be change in the future version (for instance, their namespace may be change)

Also this maybe face you with an issue in a specific field.

You have to know all of your application warning and resolve them ASAP.