为项目设置默认的构建配置 [英] Set a default build configuration for project

查看:50
本文介绍了为项目设置默认的构建配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio项目文件中有几种可能的配置.如何指定默认情况下选择的哪一个(当没有 .suo 时)?现在,当我在Visual Studio中打开项目时,默认情况下会选择调试"配置.

I have several possible configurations in a Visual Studio project file. How can I specify which one is selected by default (when no .suo is present)? Right now, when I open the project in Visual Studio, Debug configuration is selected by default.

项目文件的相关部分:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>...</ProductVersion>
    <SchemaVersion>...</SchemaVersion>
    <ProjectGuid>{...}</ProjectGuid>
    <OutputType>...</OutputType>
    <RootNamespace>...</RootNamespace>
    <AssemblyName>AAAAA</AssemblyName>
    <MyType>Windows</MyType>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>Full</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>false</Optimize>
    <OutputPath>Bin\Release</OutputPath>
    <DocumentationFile>AAAAA.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <DefineDebug>true</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <OutputPath>bin\</OutputPath>
    <DocumentationFile>AAAAA.xml</DocumentationFile>
    <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

我希望默认选择此配置:

I want this configuration to be selected by default:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>Full</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>false</Optimize>
    <OutputPath>Bin\Release</OutputPath>
    <DocumentationFile>AAAAA.xml</DocumentationFile>
</PropertyGroup>

推荐答案

Visual Studio始终通过解决方案来调用生成.每个解决方案配置都有一个(不区分大小写)名称,并将每个项目映射到其配置.可以通过 Build>配置管理器编辑解决方案配置,并在其中或工具栏的下拉菜单中选择当前活动的配置.

Visual Studio always invokes the build through a solution. Each solution configuration has a (case-insensitive) name and maps each project to its configuration. Solution configurations can be edited through Build > Configuration manager and the currently active one is selected there or in the drop-down in the toolbar.

活动的构建配置保存在解决方案用户选项文件( .suo )中.这是每个用户的配置,不应在源代码管理中进行检查.没有共享的配置.

Active build configuration is saved in solution user options file (.suo). This is a per-user configuration and should not be checked in the source control. No shared configuration exists for this.

如果不存在 .suo 文件,则VS选择配置,该配置的名称首先按字母顺序排序,但有以下几种例外情况:

If no .suo file is present, VS selects the configuration, whose name sorts alphabetically first with several exceptions:

  • 所有以"Debug"开头的名称都在"A"之前排序.
  • S1 S2 S1 之前对任意两个字符串 S1 S2 .(␣表示空格.)
  • All names starting with "Debug" sort before "A".
  • S1S2 sorts before S1 for any two strings S1 and S2. (␣ denotes a space.)

例如如果您具有此配置列表,则默认情况下会选择全部调试".如果删除列表中的第一个配置,请关闭VS并删除 *.suo 文件,默认情况下将选择列表中的下一个配置.

E.g. if you have this list of configurations, "Debug all" is selected by default. If you remove the first configuration in the list, close VS and delete the *.suo file, the next one on the list will be selected by default.


Debug all
Debug
Debugging
A release
ARelease
Release
WinterBash

请注意,VS显示不同的顺序:

Note that VS displays a different order:


A release
ARelease
Debug
Debug all
Debugging
Release
WinterBash

使用哪种解决方案?

如果直接打开项目文件(例如 MyProject.csproj ),Visual Studio会尝试找到解决方案文件.

Which solution is used?

If you open a project file (e.g. MyProject.csproj) directly, Visual Studio tries to locate a solution file.

  1. 在相同目录( MyProject.sln )中具有相同名称的解决方案是首选.如果找到,则使用它.
  2. 搜索同一目录( *.sln )中的所有其他解决方案.如果找到恰好一个,则使用它.
  3. 在父目录中搜索任何解决方案( .. \ *.sln ).如果找到恰好一个,则使用它.
  4. 否则,VS将创建一个仅包含项目的新解决方案(名为 MyProject.sln ),并在退出时询问将其保存在何处.该新解决方案的构建配置与项目的构建配置相对应.
  1. Solution with the same name in the same directory (MyProject.sln) is preferred. If it is found, it is used.
  2. Any other solutions in the same directory (*.sln) are searched. If exactly one is found, it is used.
  3. The parent directory is searched for any solutions (..\*.sln). If exactly one is found, it is used.
  4. Otherwise, VS creates a new solution (named MyProject.sln) containing only the project and asks on exit where to save it. This new solution's build configurations correspond to the ones the project has.

请注意,这在即将到来的VS 2017中可能会有所不同,因为它甚至支持没有项目的裸文件.

您可以在属性"窗口中以 Path 的形式查看解决方案的路径.(首先在解决方案资源管理器中选择解决方案.)

You can see the path to the solution as Path in Properties window. (Select the solution in Solution Explorer first.)

顺便说一句,项目文件中的第一个 PropertyGroup 指定 Configuration Platform 属性为空时MSBuild使用的默认值(未指定).Visual Studio始终指定这些属性,因此默认设置无关.

By the way, the first PropertyGroup in a project file specifies the defaults to be used by MSBuild when Configuration and Platform properties are empty (unspecified). Visual Studio always specifies these properties, so the defaults are irrelevant.

这篇关于为项目设置默认的构建配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆