“编译”页, 项目设计器 (Visual Basic)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, choose a project node (not the Solution node) in Solution Explorer. 然后在菜单栏上依次选择“项目” 、“属性” 。Then choose Project, Properties on the menu bar. “项目设计器”出现时,单击“编译”选项卡 。When the Project Designer appears, click the Compile tab.

备注

本文中的某些 Visual Studio 用户界面元素在计算机上出现的名称或位置可能会不同。Your computer might show different names or locations for some of the Visual Studio user interface elements in this article. 你可能正在使用其他版本的 Visual Studio 或其他环境设置。You may be using a different edition of Visual Studio or different environment settings. 有关详细信息,请参阅个性化设置 IDEFor more information, see Personalize the IDE.

配置和平台Configuration and Platform

通过以下设置,可选择要显示或修改的配置和平台。The following settings enable you to select the configuration and platform to display or modify.

备注

使用简化的生成配置,项目系统可确定是生成调试版本还是发行版本。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.

配置Configuration

指定要显示或修改的配置设置。Specifies which configuration settings to display or modify. 这些设置为“调试”(默认)、“发布”或“所有配置” 。The settings are Debug (default), Release, or All Configurations. 有关详细信息,请参阅了解生成配置以及如何:创建和编辑配置For more information, see Understanding Build Configurations and How to: Create and Edit Configurations.

平台Platform

指定要显示或修改的平台设置。Specifies which platform settings to display or modify. 可指定“任何 CPU”(默认)、“x64”或“x86” 。You can specify Any CPU (default), x64, or x86.

编译器配置选项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. 默认路径为 bin\Debug 或 bin\Release\。The default path is bin\Debug\ or bin\Release\.

使用简化的生成配置,项目系统可确定是生成调试版本还是发行版本。With simplified build configurations, the project system determines whether to build a debug or release version. 使用“调试”菜单 (F5) 中的“生成”命令,会将生成放置在调试位置中(无论指定的“输出路径”为何)。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.

Option Explicit 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.

此设置对应于 /optionexplicit 编译器选项。This setting corresponds to the /optionexplicit compiler option.

如果源代码文件包含 Option Explicit 语句,则语句中的 OnOff 值会替代“编译”页上的“Option Explicit”设置 。If a source code file contains an Option Explicit Statement, the On or Off value in the statement overrides the Option Explicit setting on the Compile page.

创建新项目时,将“编译”页上的“Option Explicit”设置设置为“选项”对话框中的“Option Explicit”设置 。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. 在“选项”对话框中,展开“项目和解决方案”,然后单击“VB 默认值” 。In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. “VB 默认值”中的“Option Explicit”初始默认设置为“开启” 。The initial default setting of Option Explicit in VB Defaults is On.

通常不建议将“Option Explicit”设置为 OffSetting 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 Option strict

指定是否强制执行严格类型语义。Specifies whether to enforce strict type semantics. “Option Strict”为“开启”时 ,以下情况会导致编译时错误:When Option Strict is On, the following conditions cause a compile-time error:

  • 隐式收缩转换Implicit narrowing conversions

  • 后期绑定Late binding

  • 隐式键入会导致 Object 类型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. 有关详细信息,请参阅 Option Strict 语句隐式转换和显式转换以及扩大转换和收缩转换For more information, see Option Strict Statement, Implicit and Explicit Conversions, and Widening and Narrowing Conversions.

如果将对象分配给声明为 Object 类型的变量,则该对象为晚期绑定。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. 有关详细信息,请参阅 Option Strict 语句以及早期绑定和晚期绑定For more information, see Option Strict Statement and Early and Late Binding.

如果无法为已声明的变量推断出合适的类型,则会发生隐式对象类型错误,因此 Object 类型是推断出来的。Implicit object type errors occur when an appropriate type cannot be inferred for a declared variable, so a type of Object is inferred. 这主要是在未使用 As 子句的情况下使用 Dim 语句声明变量,且 Option Infer 为关闭时发生的。This primarily occurs when you use a Dim statement to declare a variable without using an As clause, and Option Infer is off. 有关详细信息,请参阅 Option Strict 语句Option Infer 语句Visual Basic 语言规范For more information, see Option Strict Statement, Option Infer Statement, and the Visual Basic Language Specification.

“Option Strict”设置对应于 /optionstrict 编译器选项。The Option Strict setting corresponds to the /optionstrict compiler option.

如果源代码文件包含 Option Strict 语句,则语句中的 OnOff 值会替代“编译”页上的“Option Strict”设置 。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.

创建项目时,将“编译”页上的“Option Strict”设置设置为“选项”对话框中的“Option Strict”设置 。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. 在“选项”对话框中,展开“项目和解决方案”,然后单击“VB 默认值” 。In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. “VB 默认值”中的“Option Strict”初始默认设置为“关闭” 。The initial default setting of Option Strict in VB Defaults is Off.

Option Strict 各个警告Option Strict Individual Warnings

“编译”页的“警告配置”部分具有与 Option Strict 开启时引起编译时错误的三种情况相对应的设置。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

“Option Strict”设置为“开启”时,所有这三个警告配置设置都将被设置为“错误” 。When you set Option Strict to On, all three of these warning configuration settings are set to Error. “Option Strict”设置为“关闭”时,所有这三个设置都将被设置为“无” 。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. 如果三个警告配置都设置为“错误” ,则 On 会出现在 Option strict 框中。If all three warning configuration settings are set to Error, On appears in the Option strict box. 如果三个都设置为“无”,则 Off 会出现在此框中。If all three are set to None, Off appears in this box. 对于这些配置的任何其他组合,显示“(自定义)” 。For any other combination of these settings, (custom) appears.

Option compare 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.

此设置对应于 /optioncompare 编译器选项。This setting corresponds to the /optioncompare compiler option.

如果源代码文件包含 Option Compare 语句,则语句中 BinaryText 值将替代“编译”页上的“Option Compare”设置 。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.

创建项目时,将“编译”页上的“Option Compare”设置设置为“选项”对话框中的“Option Compare”设置的值 。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. 在“选项”对话框中,展开“项目和解决方案”,然后单击“VB 默认值” 。In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. “VB 默认值”中的“Option Compare”初始默认设置为“二进制” 。The initial default setting of Option Compare in VB Defaults is Binary.

Option infer 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.

此设置对应于 /optioninfer 编译器选项。This setting corresponds to the /optioninfer compiler option.

如果源代码文件包含 Option Infer 语句,则语句中的 OnOff 值会替代“编译”页上的“Option Infer”设置 。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.

创建项目时,将“编译”页上的“Option Infer”设置设置为“选项”对话框中的“Option Infer”设置的值 。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. 在“选项”对话框中,展开“项目和解决方案”,然后单击“VB 默认值” 。In the Options dialog box, expand Projects and Solutions, and then click VB Defaults. “VB 默认值”中的“Option Infer”初始默认设置为“开启” 。The initial default setting of Option Infer in VB Defaults is On.

目标 CPUTarget CPU

指定将作为输出文件目标的处理器。Specifies the processor to be targeted by the output file. 对于任何 32 位 Intel 兼容处理器,请指定“x86” ;对于任何 64 位 Intel 兼容处理器,请指定“x64” ;对于任何 ARM 处理器,请指定“ARM” ;选择“任何 CPU”,指定可接受任何处理器 。Specify x86 for any 32-bit Intel-compatible processor, x64 for any 64-bit Intel-compatible processor, ARM for any ARM processor, or Any CPU to specify that any processor is acceptable. “任何 CPU” 是新项目的默认值,因为它允许在最广泛的各类硬件上运行应用程序。Any CPU is the default value for new projects because it allows the application to run on the largest number of hardware types.

有关详细信息,请参阅 /platform (Visual Basic)For more information, see /platform (Visual Basic).

首选 32 位Prefer 32-bit

如果选中了“首选 32 位” 复选框,则应用程序可在 32 位和 64 位版本的 Windows 上作为 32 位应用程序运行。If the Prefer32-bit check box is selected, the application runs as a 32-bit application on both 32-bit and 64-bit versions of Windows. 否则,应用程序在 32 位版本的 Windows 上作为 32 位应用程序运行,而在 64 位版本的 Windows 上作为 64 位应用程序运行。Otherwise, the application runs as a 32-bit application on 32-bit versions of Windows and as a 64-bit application on 64-bit versions of Windows.

作为 64 位应用程序运行,会使指针大小增加一倍,并且可能会导致 32 位专用库的兼容性问题。Running as a 64-bit application doubles the pointer size, and it can cause compatibility problems with libraries that are exclusively 32-bit. 只有运行速度明显加快或需要超过 4 GB 的内存时,才能将应用程序作为 64 位运行。It makes sense to run an application as 64-bit only if it runs significantly faster or needs more than 4 GB of memory.

仅在以下条件都为 true 的情况下,才可使用此复选框:This check box is available only if all of the following conditions are true:

  • 在“编译”页上,“目标 CPU”列表被设置为“任何 CPU” 。On the Compile Page, the Target CPU list is set to Any CPU.

  • 在“应用程序”页上,“应用程序类型”列表指定项目为应用程序 。On the Application Page, the Application type list specifies that the project is an application.

  • 在“应用程序” 页上,“目标框架” 列表指定 .NET Framework 4.5。On the Application Page, the Target framework list specifies the .NET Framework 4.5.

警告配置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.

此设置对应于 /nowarn 编译器选项。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.

生成 XML 文档文件Generate XML documentation file

指定是否生成文档信息。Specifies whether to generate documentation information. 默认情况下,此复选框处于选中状态,指示编译器生成文档信息并将这些信息包含在一个 XML 文件中。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.

此设置对应于 /doc 编译器选项。This setting corresponds to the /doc compiler option.

“注册 COM 互操作” Register for COM interop

指定托管应用程序是否将公开一个 COM 对象(可调用 COM 的包装),以使 COM 对象可以与托管应用程序进行交互。Specifies whether your managed application will expose a COM object (a COM-callable wrapper) that enables a COM object to interact with the application.

默认情况下清除此复选框,以指定应用程序不允许 COM 互操作。By default, this check box is cleared, which specifies that the application will not allow COM interop. 选中此复选框,允许 COM 互操作。Select this check box to allow COM interop.

此选项对于“Windows 应用程序”或“控制台应用程序”项目不可用。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. 此对话框仅适用于 Visual Basic 项目。This dialog box applies to Visual Basic projects only. 有关详细信息,请参阅“生成事件”对话框 (Visual Basic)For more information, see Build Events Dialog Box (Visual Basic).

高级编译选项Advanced Compile Options

单击此按钮,访问“高级编译器设置”对话框 。Click this button to access the AdvancedCompiler Settings dialog box. 使用“高级编译器设置”对话框,指定项目的高级生成配置属性 。Use the AdvancedCompiler Settings dialog box to specify a project's advanced build configuration properties. 此对话框仅适用于 Visual Basic 项目。This dialog box applies to Visual Basic projects only. 有关详细信息,请参阅“高级编译器设置”对话框 (Visual Basic)For more information, see Advanced Compiler Settings Dialog Box (Visual Basic).

请参阅See also