C# Visual Studio 警告级别的含义?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/644011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 11:32:10  来源:igfitidea点击:

Visual Studio warning level meanings?

c#visual-studiowarningscompiler-warnings

提问by Jon Tackabury

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.

在 Web 应用程序项目的构建选项卡上,我有一个名为“警告级别”的设置。我可以设置一个从 0 到 4 的值。这些值是什么意思?值 0 是否会更严格并产生更多警告,反之亦然?我还没有找到任何关于它的文档,但也许我找错了地方。

采纳答案by mwigdahl

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

此链接向您展示了警告级别的定义(我假设您在 Web 项目中使用 C# 代码)。4 级是最严格的。



  • 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 trueor false.
  • 4: Displays all level 3 warnings plus informational warnings. This is the default warning level at the command line.
  • 0:关闭所有警告信息的发射。
  • 1:显示严重警告信息。
  • 2:显示 1 级警告以及某些不太严重的警告,例如关于隐藏班级成员的警告。
  • 3:显示级别 2 警告以及某些不太严重的警告,例如有关始终计算为truefalse 的表达式的警告。
  • 4:显示所有 3 级警告和信息警告。这是命令行中的默认警告级别。

回答by Adrian Grigore

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

0 完全关闭警告,而 4 是最详细的级别。请参阅此处具有相同警告级别的文档

回答by royatl

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.

越高越严格。看到所有对您的应用程序意义重大或意义不大的警告可能会很烦人,但花时间清除它们可以教会您很多东西。

回答by dirkgently

For example setting a warning level to 4 or /W4means 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.

例如,将警告级别设置为 4 或/W4意味着编译器会将所有警告视为错误。这主要是编译器在看到它不舒服的东西时的反应。而且,顺便说一下,所有警告的级别为 0。

回答by itsmatt

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

您可以在此处查看Microsoft 的级别。0 级基本上没有,而 4 级将是最严格的。

回答by chuckc

Additionally, F# goes up to Warning Level 5:

此外,F# 上升到警告级别 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)

--warn:警告级别

设置警告级别(0 到 5)。默认级别为 3。每个警告都根据其严重程度指定一个级别。与 1 级相比,5 级发出更多但不那么严重的警告。

5 级警告是:21(在运行时检查递归使用)、22(让 rec 无序评估)、45(完全抽象)和 52(防御性副本)

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

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