Application Page, Project Designer (Visual Basic)Application Page, Project Designer (Visual Basic)

使用项目设计器的“应用程序” 页可指定项目的应用程序设置和属性。Use the Application page of the Project Designer to specify a project's application settings and properties.

若要访问“应用程序”页,请在 解决方案资源管理器 中选择项目节点(而非“解决方案”节点)。To access the Application 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, select the Application 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.

常规应用程序设置General application settings

以下选项用于配置应用程序的常规设置。The following options enable you to configure general settings for an application.

程序集名称Assembly name

指定将包含程序集清单的输出文件的名称。Specifies the name of the output file that will contain the assembly manifest. 如果更改此属性,“输出名称” 属性也会随之更改。If you change this property, the Output Name property also changes.

此外,还可以使用 /out (Visual Basic) 编译器开关,通过命令提示符指定输出文件名。You can also specify the name of the output file from a command prompt by using the /out (Visual Basic) compiler switch.

有关如何以编程方式访问此属性的信息,请参阅 AssemblyNameFor information about how to access this property programmatically, see AssemblyName.

根命名空间Root namespace

指定项目中所有文件的基命名空间。Specifies the base namespace for all files in the project. 例如,如果将“根命名空间” 设置为 Project1,并且在代码中的任何命名空间外有 Class1,则其命名空间为 Project1.Class1For example, if you set the Root Namespace to Project1 and you have a Class1 outside of any namespace in your code, its namespace would be Project1.Class1. 如果代码中的命名空间 Class2 内有 Order,则其命名空间为 Project1.Order.Class2If you have a Class2 in a namespace Order in code, its namespace would be Project1.Order.Class2.

如果清除“根命名空间” ,则可以在代码中指定项目的命名空间结构。If you clear the Root Namespace, you can specify the namespace structure of your project in code.

备注

如果在 Namespace 语句中使用 Global 关键字,则可以在项目的根命名空间外部定义命名空间。If you use the Global keyword in a Namespace Statement, you can define a namespace out of the root namespace of your project. 如果清除“根命名空间”,无需在 Namespace 语句中使用 Global 关键字,Global 便可成为顶级命名空间。If you clear the Root Namespace, Global becomes the top-level namespace, which removes the need for the Global keyword in a Namespace statement. 有关详细信息,请参阅 Visual Basic 中的命名空间中的“Namespace 语句中的 Global 关键字”。For more information, see "Global Keyword in Namespace Statements" in Namespaces in Visual Basic.

有关如何在代码中创建命名空间的信息,请参阅 Namespace 语句For information about how to create namespaces in your code, see Namespace Statement.

有关根命名空间属性的详细信息,请参阅 /rootnamespaceFor more information about the root namespace property, see /rootnamespace.

有关如何以编程方式访问此属性的信息,请参阅 RootNamespaceFor information about how to access this property programmatically, see RootNamespace.

目标框架(所有配置)Target framework (all configurations)

指定应用程序面向的 .NET 版本。Specifies the version of .NET that the application targets. 此选项可以有不同的值,具体取决于计算机上安装的 .NET 版本。This option can have different values depending on which versions of .NET are installed on your computer.

对于 .NET Framework 项目,默认值与创建项目时指定的目标框架一致。For .NET Framework projects, the default value matches the target framework that you specified when you created the project.

备注

第一次打开对话框时将自动设置“系统必备”对话框中所列的必备组件包。The prerequisite packages that are listed in the Prerequisites Dialog Box are set automatically when you open the dialog box for the first time. 如果随后更改项目的目标框架,则必须手动指定必备组件,以便与新目标框架相匹配。If you subsequently change the project's target framework, you must specify the prerequisites manually to match the new target framework.

有关详细信息,请参阅框架定位概述For more information, see Framework targeting overview.

应用程序类型Application type

指定要生成的应用程序类型。Specifies the type of application to build. 值因项目类型而异。The values are different depending on the project type. 例如,对于“Windows 窗体应用”项目,可以指定“Windows 窗体应用程序”、“类库”、“控制台应用程序”、“Windows 服务”或“Web 控件库” 。For example, for a Windows Forms App project, you can specify Windows Forms Application, Class Library, Console Application, Windows Service, or Web Control Library.

对于 Web 应用程序项目,必须指定“类库” 。For a web application project, you must specify Class Library.

有关“应用程序类型” 属性的详细信息,请参阅 /target (Visual Basic)For more information about the Application type property, see /target (Visual Basic). 有关如何以编程方式访问此属性的信息,请参阅 OutputTypeFor information about how to access that property programmatically, see OutputType.

自动生成绑定重定向Auto-generate binding redirects

如果应用或其组件引用同一程序集的多个版本,则绑定重定向将添加到项目中。Binding redirects are added to your project if your app or its components reference more than one version of the same assembly. 如果要在项目文件中手动定义绑定重定向,请取消选中“自动生成绑定重定向” 。If you want to manually define binding redirects in the project file, deselect Auto-generate binding redirects.

有关重定向的详细信息,请参阅重定向程序集版本For more information about redirection, see Redirecting assembly versions.

启动窗体/启动对象/启动 URIStartup form / Startup object / Startup URI

指定应用程序的启动窗体或入口点。Specifies the application's startup form or entry point.

如果“启用应用程序框架” 处于选中状态(默认设置),则此列表的标题为“启动窗体” ,并且仅显示窗体,因为应用程序框架仅支持启动窗体,不支持对象。If Enable application framework is selected (the default), this list is titled Startup form and shows only forms because the application framework supports only startup forms, not objects.

如果项目是 WPF 浏览器应用程序,则此列表的标题为“启动 URI” ,默认值为“Page1.xaml” 。If the project is a WPF Browser Application, this list is titled Startup URI, and the default is Page1.xaml. “启动 URI” 列表用于指定应用程序启动时显示的用户界面资源(一种 XAML 元素)。The Startup URI list enables you to specify the user interface resource (a XAML element) that the application displays when the application starts. 有关详细信息,请参阅 StartupUriFor more information, see StartupUri.

如果“启用应用程序框架” 处于清除状态,则此列表将变为“启动对象” ,并且同时显示窗体和带有 Sub Main 的类或模块。If Enable application framework is cleared, this list becomes Startup object and shows both forms and classes or modules with a Sub Main.

“启动对象” 定义应用程序加载时要调用的入口点。Startup object defines the entry point to be called when the application loads. 此选项通常设置为应用程序中的主窗体或当应用程序启动时应运行的 Sub Main 过程。Generally this is set to either the main form in your application or to the Sub Main procedure that should run when the application starts. 类库没有入口点,因此它们为此属性提供的唯一选项是“(无)” 。Because class libraries do not have an entry point, their only option for this property is (None). 有关详细信息,请参阅 /mainFor more information, see /main. 若要以编程方式访问此属性,请参阅 StartupObjectTo access this property programmatically, see StartupObject.

图标Icon

设置要用作程序图标的 .ico 文件。Sets the .ico file that you want to use as your program icon. 选择 <Browse...> 以浏览现有图形。Select <Browse...> to browse for an existing graphic. 有关详细信息,请参阅 /win32icon(或 /win32icon(C# 编译器选项))。See /win32icon (or /win32icon (C# Compiler Options)) for more information. 若要以编程方式访问此属性,请参阅 ApplicationIconTo access this property programmatically, see ApplicationIcon.

程序集信息Assembly Information

单击此按钮以显示“程序集信息”对话框Click this button to display the Assembly Information Dialog Box.

启用应用程序框架Enable application framework

指定项目是否使用应用程序框架。Specifies whether a project will use the application framework. 此选项的设置会影响“启动窗体” /“启动对象” 中可用的选项。The setting of this option affects the options available in Startup form/Startup object.

如果选中此复选框,应用程序会使用标准 Sub MainIf this check box is selected, your application uses the standard Sub Main. 选中此复选框将启用“Windows 应用程序框架属性” 节中的功能,同时会要求选择启动窗体。Selecting this check box enables the features in the Windows application framework properties section, and also requires you to select a startup form.

如果清除此复选框,应用程序会使用“启动窗体”中指定的自定义 Sub MainIf this check box is cleared, your application uses the custom Sub Main that you specified in Startup form. 在此情况下,可以指定启动对象(方法或类中的自定义 Sub Main)或窗体。In this case you can specify either a startup object (a custom Sub Main in a method or a class) or a form. 与此同时,“Windows 应用程序框架属性” 节中的选项变为不可用。Also, the options in the Windows application framework properties section become unavailable.

查看 Windows 设置View Windows Settings

单击此按钮以生成并打开 app.manifest 文件 。Click this button to generate and open the app.manifest file. Visual Studio 使用此文件生成应用程序的清单数据。Visual Studio uses this file to generate manifest data for the application. 然后通过修改 app.manifest 中的 <requestedExecutionLevel> 标记来设置 UAC 请求的执行级别,如下所示 :Then set the UAC requested execution level by modifying the <requestedExecutionLevel> tag in app.manifest as follows:

<requestedExecutionLevel level="asInvoker" />

ClickOnce 在 asInvoker 级别或虚拟化模式下运行(无清单生成)。ClickOnce works with a level of asInvoker or in virtualized mode (no manifest generation). 若要指定虚拟化模式,请从 app.manifest 中删除整个标记。To specify virtualized mode, remove the entire tag from app.manifest.

有关清单生成的详细信息,请参阅 Windows Vista 上的 ClickOnce 部署For more information about manifest generation, see ClickOnce Deployment on Windows Vista.

Windows 应用程序框架属性Windows application framework properties

“Windows 应用程序框架属性” 节提供以下设置。The following settings are available in the Windows application framework properties section. 仅当“启用应用程序框架” 复选框处于选中状态时,这些选项才可用。These options are available only if the Enable application framework check box is selected.

提示

本部分后面的一节介绍了特定于 Windows Presentation Foundation (WPF) 应用的“Windows 应用程序框架属性”设置 。The section following this one describes Windows application framework properties settings specific to Windows Presentation Foundation (WPF) apps.

启用 XP 视觉样式Enable XP visual styles

启用或禁用 Windows XP 视觉样式,也称为 Windows XP 主题Enables or disables the Windows XP visual styles, also known as Windows XP Themes. Windows XP 视觉样式可启用一些控件,例如带有圆角和动态颜色的控件。Windows XP visual styles enable, for example, controls with rounded corners and dynamic colors. 默认为已启用。The default is enabled.

生成一个实例应用程序Make single instance application

选中此复选框可防止用户运行应用程序的多个实例。Select this check box to prevent users from running multiple instances of the application. 此复选框默认处于清除 状态,这样就可以运行多个应用程序实例了。The default setting for this check box is cleared, which allows multiple instances of the application to be run. 有关详细信息,请参阅 StartupNextInstance 事件。For more information, see the StartupNextInstance event.

关闭时保存 My.SettingsSave My.Settings on Shutdown

选中此复选框以指定用户关闭其计算机时保存应用程序的 My.Settings 设置。Select this check box to specify that the application's My.Settings settings are saved when users shut down their computers. 默认设置为已启用。The default setting is enabled. 如果此选项处于禁用状态,可通过调用 My.Settings.Save 手动保存应用程序设置。If this option is disabled, you can save application settings manually by calling My.Settings.Save.

身份验证模式Authentication mode

选择“Windows” (默认值)以指定使用 Windows 身份验证来标识当前登录的用户。Select Windows (the default) to specify the use of Windows authentication to identify the currently logged-on user. 可以使用 My.User 对象在运行时检索此信息。You can retrieve this information at run time by using the My.User object. 如果要提供自己的代码来对用户进行身份验证,而不是使用默认的 Windows 身份验证方法,则选择“由应用程序定义” 。Select Application-defined if you will provide your own code to authenticate users instead of using the default Windows authentication methods.

关闭模式Shutdown mode

选择“当启动窗体关闭时” (默认值)以指定应用程序在设置为启动窗体的窗体关闭时退出,即使其他窗体处于打开状态也是如此。Select When startup form closes (the default) to specify that the application exit when the form set as the startup form closes, even if other forms are open. 选择“当最后一个窗体关闭时” 以指定应用程序在最后一个窗体关闭或者显式调用 My.Application.ExitEnd 语句时退出。Select When last form closes to specify that the application exit when the last form is closed or when My.Application.Exit or the End statement is called explicitly.

选择“在显式关闭时” 以指定应用程序在用户显式调用 Shutdown 时退出。Select On explicit shutdown to specify that the application exit when you explicitly call Shutdown.

选择“在最后一个窗口关闭时” 以指定应用程序在最后一个窗口关闭或者用户显式调用 Shutdown 时退出。Select On last window close to specify that the application exit when the last window closes or when you explicitly call Shutdown. 此为默认设置。This is the default setting.

选择“在主窗口关闭时” 以指定应用程序在主窗口关闭或者用户显式调用 Shutdown 时退出。Select On main window close to specify that the application exit when the main window closes or when you explicitly call Shutdown.

初始屏幕Splash screen

选择要用作初始屏幕的窗体。Select the form that you want to use as a splash screen. 之前必须使用过窗体或模板来创建初始屏幕。You must have previously created a splash screen by using a form or a template. 默认值为“(无)” 。The default is (None).

查看应用程序事件View Application Events

单击此按钮以显示可以在其中为应用程序框架事件 StartupShutdownUnhandledExceptionStartupNextInstanceNetworkAvailabilityChanged 写入事件的事件代码文件。Click this button to display an events code file in which you can write events for the application framework events Startup, Shutdown, UnhandledException, StartupNextInstance and NetworkAvailabilityChanged. 还可以重写某些应用程序框架方法。You can also override certain application framework methods. 例如,可以通过重写 OnInitialize 来更改初始屏幕的显示行为。For example, you can change the display behavior of the splash screen by overriding OnInitialize.

Windows Presentation Foundation (WPF) 应用的 Windows 应用程序框架属性Windows application framework properties for Windows Presentation Foundation (WPF) apps

当项目为 Windows Presentation Foundation (WPF) 应用时,“Windows 应用程序框架属性”部分提供以下设置 。The following settings are available in the Windows application framework properties section when the project is a Windows Presentation Foundation (WPF) app. 仅当“启用应用程序框架” 复选框处于选中状态时,这些选项才可用。These options are available only if the Enable application framework check box is selected. 此表中列出的选项仅适用于 WPF 或 WPF 浏览器应用程序。The options listed in this table are available only for WPF or WPF browser applications. 不适用于 WPF 用户控件或自定义控件库。They are not available for WPF User Control or Custom Control libraries.

关闭模式Shutdown mode

此属性仅适用于 Windows Presentation Foundation (WPF) 应用程序。This property is applicable only to Windows Presentation Foundation (WPF) applications.

选择“在显式关闭时” 以指定应用程序在用户显式调用 Shutdown 时退出。Select On explicit shutdown to specify that the application exit when you explicitly call Shutdown.

选择“在最后一个窗口关闭时” 以指定应用程序在最后一个窗口关闭或者用户显式调用 Shutdown 时退出。Select On last window close to specify that the application exit when the last window closes or when you explicitly call Shutdown. 此为默认设置。This is the default setting.

选择“在主窗口关闭时” 以指定应用程序在主窗口关闭或者用户显式调用 Shutdown 时退出。Select On main window close to specify that the application exit when the main window closes or when you explicitly call Shutdown.

有关使用此设置的详细信息,请参阅 ShutdownFor more information about using this setting, see Shutdown

编辑 XAMLEdit XAML

此按钮在 XAML 编辑器中打开应用程序定义文件 (Application.xaml)。This button opens the application definition file (Application.xaml) in the XAML editor. 单击此按钮时,Application.xaml 将在应用程序定义节点处打开 。When you click this button, Application.xaml opens at the application definition node. 可能需要编辑此文件才能执行某些任务,例如定义资源。You might have to edit this file to perform certain tasks, such as defining resources. 如果应用程序定义文件不存在,项目设计器将创建一个。If the application definition file does not exist, the Project Designer creates one.

查看应用程序事件View Application Events

此按钮在代码编辑器中显示 Application 类文件 (Application.xaml.vb )。This button opens the Application class file (Application.xaml.vb) in a code editor. 如果该文件不存在,项目设计器将创建一个具有适当类名和命名空间的此类文件。If the file does not exist, the Project Designer creates one with the appropriate class name and namespace.

Application 对象在应用程序状态出现某些变化时(例如,在应用程序启动或关闭时)引发事件。The Application object raises events when certain application state changes occur (for example, on application startup or shutdown). 有关此类公开的事件的完整列表,请参阅 ApplicationFor a full list of the events that this class exposes, see Application. 这些事件在 Application 分部类的用户代码节中进行处理。These events are handled in the user code section of the Application partial class.