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?

5
  • 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.
    – James Gaunt
    Jun 6, 2011 at 8: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.
    – Mohammad Nezhad
    Jun 6, 2011 at 8: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 6, 2011 at 9:33
  • 1
    It also worth mentioning the VS static analysis and code contracts - it will add some more warnings.
    – SK-logic
    Jun 6, 2011 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. Jun 6, 2011 at 13:18

2 Answers 2

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.

3
  • 2
    Well said. Which also indicates that it's a "red flag" if developers ignore warnings entirely because "it still compiles". Jun 6, 2011 at 12:30
  • i think warnings as errors is a little extreme, especially when building web apps and vs complains about css it doesn't understand.
    – Steve
    Jun 6, 2011 at 16:57
  • @Steve: Yes - it doesn't suit all circumstances. Jun 6, 2011 at 17:01
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.