Visual Studio warning level meanings?

C#Visual StudioWarningsCompiler Warnings

C# Problem Overview


On the build tab in a Web Application project I have a setting called "Warning Level". I can set a value from 0 to 4. What do these values mean? Will a value of 0 be more strict and generate more warnings, or vice versa? I haven't been able to find any documentation on it yet, but perhaps I'm looking in the wrong place.

C# Solutions


Solution 1 - C#

This link shows you the definitions of the warning levels (I'm assuming you are using C# code in your web project). Level 5 is the most strict.


  • 0: Turns off emission of all warning messages.
  • 1: Displays severe warning messages.
  • 2: Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members.
  • 3: Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false.
  • 4: Displays all level 3 warnings plus informational warnings. This is the default warning level at the command line.
  • 5: Displays level 4 warnings plus additional warnings from the compiler shipped with C# 9.0.

Anything greater than 5 is treated as 5.

Solution 2 - C#

Higher is stricter. It can be annoying to see all the warnings that may or may not mean much to your app, but taking the time to clear them up can teach you a lot.

Solution 3 - C#

0 turns off warnings completely, while 4 is the most verbose level. See the documentation here which has the same warning levels.

Solution 4 - C#

You can check Microsoft's levels here. Level 0 is essentially none while level 4 will be the most strict.

Solution 5 - C#

Additionally, F# goes up to Warning Level 5:

>--warn:warning-level > >Sets a warning level (0 to 5). The default level is 3. Each warning is given a level based on its severity. Level 5 gives more, but less severe, warnings than level 1. > >Level 5 warnings are: 21 (recursive use checked at runtime), 22 (let rec evaluated out of order), 45 (full abstraction), and 52 (defensive copy)

https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options

Solution 6 - C#

For example setting a warning level to 4 or /W4 means the compiler will treat all warnings as errors. It's mostly how the compiler reacts when it sees something that it doesn't feel good about. And, by the way, a level of 0 turns of all warnings.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJon TackaburyView Question on Stackoverflow
Solution 1 - C#mwigdahlView Answer on Stackoverflow
Solution 2 - C#royatlView Answer on Stackoverflow
Solution 3 - C#Adrian GrigoreView Answer on Stackoverflow
Solution 4 - C#itsmattView Answer on Stackoverflow
Solution 5 - C#chuckcView Answer on Stackoverflow
Solution 6 - C#dirkgentlyView Answer on Stackoverflow