Share via


Compile Page, Project Designer (Visual Basic)

Use the Compile page of the Project Designer to specify compilation instructions. You can also specify advanced compiler options and pre-build or post-build events on this page.

To access the Compile page, select a project node in Solution Explorer, and then, on the Project menu, click Properties. When the Project Designer appears, click the Compile tab.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

Configuration and Platform

The following settings enable you to select the configuration and platform to display or modify.

Note

With simplified build configurations, the project system determines whether to build a debug or release version. Therefore, the Configuration and Platform lists are not displayed. For more information, see Debug and Release Project Configurations.

Compiler Configuration Options

The following settings enable you to set the compiler configuration options.

  • Build output path
    Specifies the location of the output files for this project's configuration. Type the path of the build output in this box, or click the Browse button to select a path. Note that the path is relative; if you enter an absolute path, it will be saved as relative. The default path is bin\Debug\ or bin\Release\. For more information, see Debug and Release Project Configurations.

    With simplified build configurations, the project system determines whether to build a debug or release version. The Build command from the Debug menu (F5) will put the build in the debug location regardless of the Output path you specify. However, the Build command from the Build menu puts it in the location you specify. For more information, see Debug and Release Project Configurations.

  • Option explicit
    Specifies whether to allow implicit declaration of variables. Select On to require explicit declaration of variables. This causes the compiler to report errors if variables are not declared before they are used. Select Off to allow implicit declaration of variables.

    This setting corresponds to the /optionexplicit compiler option.

    If a source code file contains an Option Explicit Statement (Visual Basic), the On or Off value in the statement overrides the Option Explicit setting on the Compile page.

    When you create a new project, the Option Explicit setting on the Compile page is set to the value of the Option Explicit setting in the Options dialog box. To view or change the setting in this dialog box, on the Tools menu, click Options. In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. The initial default setting of Option Explicit in VB Defaults is On.

    Setting Option Explicit to Off is generally not a good practice. You could misspell a variable name in one or more locations, which would cause unexpected results when the program is run.

  • Option strict
    Specifies whether to enforce strict type semantics. When Option Strict is On, the following conditions cause a compile-time error:

    • Implicit narrowing conversions

    • Late binding

    • Implicit typing that results in an Object type

    Implicit narrowing conversion errors occur when there is an implicit data type conversion that is a narrowing conversion. For more information, see Option Strict Statement, Implicit and Explicit Conversions (Visual Basic), and Widening and Narrowing Conversions (Visual Basic).

    An object is late bound when it is assigned to a property or method of a variable that is declared to be of type Object. For more information, see Option Strict Statement and Early and Late Binding (Visual Basic).

    Implicit object type errors occur when an appropriate type cannot be inferred for a declared variable, so a type of Object is inferred. This primarily occurs when you use a Dim statement to declare a variable without using an As clause, and Option Infer is off. For more information, see Option Strict Statement, Option Infer Statement, and the Visual Basic Language Specification.

    The Option Strict setting corresponds to the /optionstrict compiler option.

    If a source code file contains an Option Strict Statement, the On or Off value in the statement overrides the Option Strict setting on the Compile page.

    When you create a project, the Option Strict setting on the Compile page is set to the value of the Option Strict setting in the Options dialog box. To view or change the setting in this dialog box, on the Tools menu, click Options. In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. The initial default setting of Option Strict in VB Defaults is Off.

    Option Strict Individual Warnings. The Warning configurations section of the Compile page has settings that correspond to the three conditions that cause a compile-time error when Option Strict is on. Following are these settings:

    • Implicit conversion

    • Late binding; call could fail at run time

    • Implicit type; object assumed

    When you set Option Strict to On, all three of these warning configuration settings are set to Error. When you set Option Strict to Off, all three settings are set to None.

    You can individually change each warning configuration setting to None, Warning, or Error. If all three warning configuration settings are set to Error, On appears in the Option strict box. If all three are set to None, Off appears in this box. For any other combination of these settings, (custom) appears.

  • Option compare
    Specifies the type of string comparison to use. Select Binary to instruct the compiler to use binary, case-sensitive string comparisons. Select Text to use locale-specific, case-insensitive text string comparisons.

    This setting corresponds to the /optioncompare compiler option.

    If a source code file contains an Option Compare Statement, the Binary or Text value in the statement overrides the Option Compare setting on the Compile page.

    When you create a project, the Option Compare setting on the Compile page is set to the value of the Option Compare setting in the Options dialog box. To view or change the setting in this dialog box, on the Tools menu, click Options. In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. The initial default setting of Option Compare in VB Defaults is Binary.

  • Option infer
    Specifies whether to allow local type inference in variable declarations. Select On to allow the use of local type inference. Select Off to block local type inference.

    This setting corresponds to the /optioninfer compiler option.

    If a source code file contains an Option Infer Statement, the On or Off value in the statement overrides the Option Infer setting on the Compile page.

    When you create a project, the Option Infer setting on the Compile page is set to the value of the Option Infer setting in the Options dialog box. To view or change the setting in this dialog box, on the Tools menu, click Options. In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. The initial default setting of Option Infer in VB Defaults is On.

  • Warning configurations
    This table lists build conditions and the corresponding notification level of None, Warning, or Error for each.

    By default, all compiler warnings are added to the Task List during compilation. Select Disable all warnings to instruct the compiler not to issue warnings or errors. Select Treat all warnings as errors if you want the compiler to treat warnings as errors that must be fixed.

  • Disable all warnings
    Specifies whether to allow the compiler to issue notifications as specified in the Condition and Notification table described earlier in this document. By default, this check box is cleared. Select this check box to instruct the compiler not to issue warnings or errors.

    This setting corresponds to the /nowarn compiler option.

  • Treat all warnings as errors
    Specifies how to treat warnings. By default, this check box is cleared, so that all warning notifications remain set to Warning. Select this check box to change all warning notifications to Error.

    This option is available only if Disable all warnings is cleared.

  • Generate XML documentation file
    Specifies whether to generate documentation information. By default, this check box is selected, instructing the compiler to generate documentation information and include it in an XML file. Clear this check box to instruct the compiler not to create documentation.

    This setting corresponds to the /doc compiler option.

  • Register for COM interop
    Specifies whether your managed application will expose a COM object (a COM-callable wrapper) that enables a COM object to interact with the application.

    By default, this check box is cleared, which specifies that the application will not allow COM interop. Select this check box to allow COM interop.

    This option is not available for Windows Application or Console Application projects.

  • Build Events
    Click this button to access the Build Events dialog box. Use this dialog box to specify pre-build and post-build configuration instructions for the project. This dialog box applies to Visual Basic projects only. For more information, see Build Events Dialog Box (Visual Basic).

  • Advanced Compile Options
    Click this button to access the Advanced Compiler Settings dialog box. Use the Advanced Compiler Settings dialog box to specify a project's advanced build configuration properties. This dialog box applies to Visual Basic projects only. For more information, see Advanced Compiler Settings Dialog Box (Visual Basic).

See Also

Tasks

How to: Enable or Disable Compiler Warnings (Visual Basic)

How to: Set Compiler Optimizations (Visual Basic)

How to: Set Compiler Options (Visual Basic)

How to: Generate XML Documentation for a Project

How to: Register a Component for COM Interop

How to: Set Compilation Constants (Visual Basic)

How to: Optimize an Application for a Specific CPU Type

How to: Specify a Base Address for a DLL

How to: Specify Build Events (Visual Basic)

How to: Create and Edit Configurations

Reference

Debug and Release Project Configurations

General, Projects and Solutions, Options Dialog Box

Other Resources

Managing Compilation Properties

Visual Basic Command-Line Compiler

Change History

Date

History

Reason

April 2011

Added information about the Option explicit, Option strict, Option compare, and Option infer settings.

Information enhancement.