-warnaserror (Visual Basic)-warnaserror (Visual Basic)

使编译器将第一次出现的警告视为错误。Causes the compiler to treat the first occurrence of a warning as an error.

语法Syntax

-warnaserror[+ | -][:numberList]  

自变量Arguments

术语Term 定义Definition
+ | -+ | - 可选。Optional. 默认情况下,-warnaserror- 生效;警告不会阻止编译器生成输出文件。By default, -warnaserror- is in effect; warnings do not prevent the compiler from producing an output file. -warnaserror 选项与 -warnaserror+ 相同,会导致将警告视为错误。The -warnaserror option, which is the same as -warnaserror+, causes warnings to be treated as errors.
numberList 可选。Optional. -warnaserror 选项适用的警告 ID 编号列表,以逗号分隔。Comma-delimited list of the warning ID numbers to which the -warnaserror option applies. 如果未指定警告 ID,则 -warnaserror 选项适用于所有警告。If no warning ID is specified, the -warnaserror option applies to all warnings.

备注Remarks

-warnaserror 选项将所有警告视为错误。The -warnaserror option treats all warnings as errors. 通常将报告为警告的任何消息都报告为错误。Any messages that would ordinarily be reported as warnings are instead reported as errors. 编译器将随后出现的相同警告报告为警告。The compiler reports subsequent occurrences of the same warning as warnings.

默认情况下,-warnaserror- 生效,导致警告仅提供信息。By default, -warnaserror- is in effect, which causes the warnings to be informational only. -warnaserror 选项与 -warnaserror+ 相同,会导致将警告视为错误。The -warnaserror option, which is the same as -warnaserror+, causes warnings to be treated as errors.

如果希望仅将一些特定警告视为错误,则可以指定视为错误的警告编号的逗号分隔列表。If you want only a few specific warnings to be treated as errors, you may specify a comma-separated list of warning numbers to treat as errors.

备注

-warnaserror 选项不控制警告的显示方式。The -warnaserror option does not control how warnings are displayed. 使用 -nowarn 选项来禁用警告。Use the -nowarn option to disable warnings.

设置 -warnaserror 以将所有警告视为 Visual Studio IDE 中的错误To set -warnaserror to treat all warnings as errors in the Visual Studio IDE
1.在 “解决方案资源管理器” 中选择一个项目。1. Have a project selected in Solution Explorer. 在“项目”菜单上,单击“属性” 。On the Project menu, click Properties.
2.单击“编译” 选项卡。2. Click the Compile tab.
3.确保“禁用所有警告” 复选框处于未选中状态。3. Make sure the Disable all warnings check box is unchecked.
4.选中“将所有警告视为错误” 复选框。4. Check the Treat all warnings as errors check box.
设置 -warnaserror 以将特定警告视为 Visual Studio IDE 中的错误To set -warnaserror to treat specific warnings as errors in the Visual Studio IDE
1.在 “解决方案资源管理器” 中选择一个项目。1. Have a project selected in Solution Explorer. 在“项目”菜单上,单击“属性” 。On the Project menu, click Properties.
2.单击“编译” 选项卡。2. Click the Compile tab.
3.确保“禁用所有警告” 复选框处于未选中状态。3. Make sure the Disable all warnings check box is unchecked.
4.确保“将所有警告视为错误” 复选框处于未选中状态。4. Make sure the Treat all warnings as errors check box is unchecked.
5.从应将其视为错误的警告旁的“通知” 列中选择“错误” 。5. Select Error from the Notification column adjacent to the warning that should be treated as an error.

示例Example

以下代码编译 In.vb 并指示编译器在第一次发现每个警告时显示错误。The following code compiles In.vb and directs the compiler to display an error for the first occurrence of every warning it finds.

vbc -warnaserror in.vb  

示例Example

以下代码编译 T2.vb 并仅将未使用的本地变量 (42024) 的警告视为错误。The following code compiles T2.vb and treats only the warning for unused local variables (42024) as an error.

vbc -warnaserror:42024 t2.vb  

请参阅See also