了解生成配置Understand build configurations

需要生成具有不同设置的项目时,生成配置是必备项。You need build configurations when you need to build your projects with different settings. 例如,“调试” 和“发布” 是配置,在生成这些项时,将相应地使用不同的编译器选项。For example, Debug and Release are configurations and different compiler options are used accordingly when building them. 一种配置处于活动状态,并显示在 IDE 顶部的命令栏中。One configuration is active and is indicated in the command bar at the top of the IDE.

活动配置

备注

本主题适用于 Visual Studio Windows 版。This topic applies to Visual Studio on Windows. 对于 Visual Studio for Mac,请参阅在 Visual Studio for Mac 中生成配置For Visual Studio for Mac, see Build configurations in Visual Studio for Mac.

用于存储生成的输出文件的配置和平台控件。The configuration and the platform control where built output files are stored. 通常,在 Visual Studio 生成项目时,会将输出放置在以活动配置命名的项目子文件夹中(例如,“bin/Debug/x86” ),这是可以更改的。Normally, when Visual Studio builds your project, the output is placed in a project subfolder named with the active configuration (for example, bin/Debug/x86), but you can change that.

可以在解决方案和项目级别创建自己的生成配置。You can create your own build configurations at the solution and project level. 解决方案配置确定该配置处于活动状态时在生成中包含哪些项目。The solution configuration determines which projects are included in the build when that configuration is active. 将仅生成在活动解决方案配置中指定的项目。Only the projects that are specified in the active solution configuration will be built. 如果在配置管理器中选择了多个目标平台,则将生成适用于该平台的所有项目。If multiple target platforms are selected in Configuration Manager, all projects that apply to that platform are built. 项目配置确定生成项目时使用的生成设置和编译器选项。The project configuration determines what build settings and compiler options are used when you build the project.

若要创建、选择、修改或删除配置,可以使用“配置管理器” 。To create, select, modify, or delete a configuration, you can use the Configuration Manager. 若要打开它,请在菜单栏上选择“生成” > “配置管理器” ,或者直接在搜索框中键入“配置” 。To open it, on the menu bar, choose Build > Configuration Manager, or just type Configuration in the search box. 也可以使用“标准” 工具栏上的“解决方案配置” 列表,选择配置或打开“配置管理器” 。You can also use the Solution Configurations list on the Standard toolbar to select a configuration or open the Configuration Manager.

配置管理器

备注

如果在工具栏上找不到解决方案配置设置且无法访问“配置管理器” ,Visual BasicVisual Basic 开发设置可能适用。If you can't find solution configuration settings on the toolbar and can't access the Configuration Manager, Visual BasicVisual Basic development settings may be applied. 有关详细信息,请参阅如何:在应用 Visual Basic 开发人员设置后管理生成配置For more information, see How to: Manage configurations with Visual Basic developer settings applied.

默认情况下,“调试” 和“发布” 配置包含在使用 Visual StudioVisual Studio 模板创建的项目中。By default, Debug and Release configurations are included in projects that are created by using Visual StudioVisual Studio templates. “调试” 配置支持调试应用,而“发布” 配置生成可部署的应用的版本。A Debug configuration supports the debugging of an app, and a Release configuration builds a version of the app that can be deployed. 有关详细信息,请参阅如何:设置调试和发布配置For more information, see How to: Set debug and release configurations. 还可以创建自定义解决方案配置和项目配置。You can also create custom solution configurations and project configurations. 有关详细信息,请参阅如何:创建和编辑配置For more information, see How to: Create and edit configurations.

解决方案配置Solution configurations

解决方案配置指定如何生成和部署解决方案中的项目。A solution configuration specifies how projects in the solution are to be built and deployed. 若要修改解决方案配置或定义新的配置,请在“配置管理器” 中的“活动解决方案配置” 下,选择“编辑” 或“新建” 。To modify a solution configuration or define a new one, in the Configuration Manager, under Active solution configuration, choose Edit or New.

解决方案配置的“项目上下文” 框中的每个条目均表示解决方案中的一个项目。Each entry in the Project contexts box in a solution configuration represents a project in the solution. 对于“活动解决方案配置” 和“活动解决方案平台” 的每个组合,都可以设置每个项目的使用方式。For every combination of Active solution configuration and Active solution platform, you can set how each project is used. (有关解决方案平台的详细信息,请参阅了解生成平台。)(For more information about solution platforms, see Understand build platforms.)

在定义新的解决方案配置并选中“创建新的项目配置” 复选框后,Visual StudioVisual Studio 会自动将新的配置分配给所有项目。When you define a new solution configuration and select the Create new project configurations check box, Visual StudioVisual Studio automatically assigns the new configuration to all of the projects. 同样,在定义新的解决方案平台并选中“创建新的项目平台” 复选框后,Visual StudioVisual Studio 也会自动将新的平台分配给所有项目。Likewise, when you define a new solution platform and select the Create new project platforms check box, Visual StudioVisual Studio automatically assigns the new platform to all of the projects. 此外,如果您添加一个面向新平台的项目,则 Visual Studio 会将该平台添加到解决方案平台列表中并将其分配给所有项目。Also, if you add a project that targets a new platform, Visual Studio adds that platform to the list of solution platforms and assigns it to all of the projects. 您仍可以修改每个项目的设置。You can still modify the settings for each project.

活动解决方案配置还为 IDE 提供了上下文。The active solution configuration also provides context to the IDE. 例如,如果处理的是项目,并且配置指定将针对移动设备生成,那么“工具箱” 只会显示可在移动设备项目中使用的项。For example, if you're working on a project and the configuration specifies that it will be built for a mobile device, the Toolbox displays only items that can be used in a mobile device project.

项目配置Project configurations

项目针对的配置和平台结合使用以指定在生成时要使用的生成设置和编译器选项。The configuration and platform that a project targets are used together to specify the build settings and compiler options to use when it's built. 对于配置和平台的每种组合,项目可以具有不同的设置。A project can have different settings for each combination of configuration and platform. 要修改项目属性,请在“解决方案资源管理器” 中打开项目的快捷菜单,然后选择“属性” 。To modify the properties of a project, open the shortcut menu for the project in Solution Explorer, and then choose Properties. 在项目设计器的“生成” 选项卡的顶部,选择活动配置以编辑其生成设置。At the top of the Build tab of the project designer, choose an active configuration to edit its build settings.

项目设计器配置

生成多个配置Building multiple configurations

使用“生成” > “生成解决方案” 命令生成解决方案时,Visual Studio 只会生成活动配置。When you build a solution using the Build > Build Solution command, Visual Studio only builds the active configuration. 将生成在该解决方案配置中指定的所有项目,并且生成的唯一项目配置是活动解决方案配置和活动解决方案平台中指定的项目配置,该配置在 Visual Studio 的工具栏中显示。All projects that are specified in that solution configuration are built, and the only project configuration that's built is that one specified in the active solution configuration and active solution platform, which is shown in the toolbar in Visual Studio. 例如:“调试” 和“x86” 。For example, Debug and x86. 不会生成其他定义的配置和平台。Other defined configurations and platforms are not built.

如果要在一个操作中生成多个配置和平台,可以使用 Visual Studio 中的“生成” > “批生成” 选项。If you want to build multiple configurations and platforms in one action, you can use the Build > Batch Build option in Visual Studio. 若要访问此功能,请按 Ctrl +Q 打开搜索框,然后输入 Batch buildTo access this feature, press Ctrl+Q to open the search box, and enter Batch build. 批生成并非适用于所有项目类型。Batch build is not available for all project types. 请参阅如何:同时生成多个配置See How to: Build multiple configurations simultaneously.

Visual Studio 如何分配项目配置How Visual Studio assigns project configurations

在定义新的解决方案配置且未复制现有配置中的设置时,Visual Studio 会使用以下标准来分配默认的项目配置。When you define a new solution configuration and don't copy settings from an existing one, Visual Studio uses the following criteria to assign default project configurations. 按所示顺序对条件进行评估。The criteria are evaluated in the order shown.

  1. 如果项目的配置名称与新解决方案配置的名称完全匹配 (<configuration name> <platform name>),则分配此配置。If a project has a configuration name (<configuration name> <platform name>) that exactly matches the name of the new solution configuration, that configuration is assigned. 配置名称不区分大小写。Configuration names are not case-sensitive.

  2. 如果项目有一个与新解决方案配置的名称部分匹配的配置名称,则分配该配置,无论平台部分是否匹配。If the project has a configuration name in which the configuration-name part matches the new solution configuration, that configuration is assigned, whether the platform portion matches or not.

  3. 如果仍没有匹配项,则分配项目中列出的第一个配置。If there is still no match, the first configuration that's listed in the project is assigned.

Visual Studio 如何分配解决方案配置How Visual Studio assigns solution configurations

创建项目配置(在“配置管理器” 中,在相应项目的“配置” 列中选择下拉菜单中的“新建” )并选中“创建新的解决方案配置” 复选框后,Visual Studio 会查找名称相似的解决方案配置,以在它支持的每个平台上生成项目。When you create a project configuration (in the Configuration Manager, by choosing New on the drop-down menu in the Configuration column for that project) and select the Create new solution configurations check box, Visual Studio looks for a like-named solution configuration to build the project on each platform it supports. 在某些情况下,Visual Studio 会重命名现有解决方案配置或定义新的配置。In some cases, Visual Studio renames existing solution configurations or defines new ones.

Visual Studio 使用以下标准来分配解决方案配置。Visual Studio uses the following criteria to assign solution configurations.

  • 如果项目配置未指定平台或仅指定一个平台,则将查找或添加一个其名称与新项目配置名称匹配的解决方案配置。If a project configuration doesn't specify a platform or specifies just one platform, then a solution configuration whose name matches that of the new project configuration is either found or added. 此解决方案配置的默认名称不包含平台名称;它采用的形式为 <project configuration name>。The default name of this solution configuration does not include a platform name; it takes the form <project configuration name>.

  • 如果项目支持多个平台,则可为每个受支持的平台找到或添加解决方案配置。If a project supports multiple platforms, a solution configuration is either found or added for each supported platform. 每个解决方案配置的名称均包含项目配置名称和平台名称,并采用 <project configuration name> <platform name> 的形式。The name of each solution configuration includes both the project configuration name and the platform name, and has the form <project configuration name> <platform name>.

请参阅See also