Partilhar via


/warnaserror (Visual Basic)

Causes the compiler to treat the first occurrence of a warning as an error.

/warnaserror[+ | -][:numberList]

Arguments

Term

Definition

+ | -

Optional. By default, /warnaserror- is in effect; warnings do not prevent the compiler from producing an output file. The /warnaserror option, which is the same as /warnaserror+, causes warnings to be treated as errors.

numberList

Optional. Comma-delimited list of the warning ID numbers to which the /warnaserror option applies. If no warning ID is specified, the /warnaserror option applies to all warnings.

Remarks

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.

By default, /warnaserror- is in effect, which causes the warnings to be informational only. 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.

Note

The /warnaserror option does not control how warnings are displayed. Use the /nowarn option to disable warnings.

To set /warnaserror to treat all warnings as errors in the Visual Studio IDE

  1. Have a project selected in Solution Explorer. On the Project menu, click Properties. For more information, see Introduction to the Project Designer.

  2. Click the Compile tab.

  3. Make sure the Disable all warnings check box is unchecked.

  4. Check the Treat all warnings as errors check box.

To set /warnaserror to treat specific warnings as errors in the Visual Studio IDE

  1. Have a project selected in Solution Explorer. On the Project menu, click Properties.

  2. Click the Compile tab.

  3. Make sure the Disable all warnings check box is unchecked.

  4. Make sure the Treat all warnings as errors check box is unchecked.

  5. Select Error from the Notification column adjacent to the warning that should be treated as an error.

Example

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

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

Reference

Sample Compilation Command Lines (Visual Basic)

Concepts

Configuring Warnings in Visual Basic

Other Resources

Visual Basic Command-Line Compiler