Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a default build configuration for project

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>
like image 260
hsim Avatar asked Nov 16 '15 21:11

hsim


People also ask

What is a build configuration?

A build configuration is a collection of settings used to start a build and group the sequence of the builds in the UI. Examples of build configurations are distribution, integration tests, prepare release distribution, "nightly" build. A build configuration belongs to a project and contains builds.

How do you add a configuration to a project?

Create a project configurationSelect a project in the Project column. In the Configuration drop-down list for that project, choose New. The New Project Configuration dialog box opens. In the Name box, enter a name for the new configuration.

How do I change the build configuration in Intellij?

From the main menu, select Run | Edit Configurations. Alternatively, press Alt+Shift+F10 , then 0 . In the left-hand pane of the run/debug configuration dialog, click Edit configuration templates…. In the Run/Debug Configuration Templates dialog that opens, select a configuration type.


1 Answers

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".
  • S1S2 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.

  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.

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.

like image 130
Palec Avatar answered Nov 03 '22 23:11

Palec