问题
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.
Relevant part of the project file:
<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>
回答1:
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.
Which solution build configuration is used?
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.
If no .suo
file is present, VS selects the configuration, whose name sorts alphabetically first with several exceptions:
- All names starting with "Debug" sort before "A".
- S1␣S2 sorts before S1 for any two strings S1 and S2. (␣ denotes a space.)
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
Note that VS displays a different order:
A release ARelease Debug Debug all Debugging Release WinterBash
Which solution is used?
If you open a project file (e.g. MyProject.csproj
) directly, Visual Studio tries to locate a solution file.
- Solution with the same name in the same directory (
MyProject.sln
) is preferred. If it is found, it is used. - Any other solutions in the same directory (
*.sln
) are searched. If exactly one is found, it is used. - The parent directory is searched for any solutions (
..\*.sln
). If exactly one is found, it is used. - 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.
Note that this is probably going to be different in the upcoming VS 2017 as it supports even bare files without projects.
You can see the path to the solution as Path in Properties window. (Select the solution in Solution Explorer first.)
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.
回答2:
I believe the build configurations are listed alphabetically. Meaning the "Debug" configuration will be the default item. And "Release" will not be. If you wish Release to be the default configuration you can create a new build configuration and ensure it is displayed before "Debug", by using the alphabetic sorting, e.g. name the build configuration "ARelease". Not a perfect solution, but it works.
来源:https://stackoverflow.com/questions/33744624/set-a-default-build-configuration-for-project