#497 – Creating a New Build Configuration in a Project

In Visual Studio, you manage both build configurations, for each project, and solution configurations.  The project-level configurations specify sets of build options.  The solution-level configurations specify which project-level configurations are associated with each solution configuration.

You create and edit both project-level and solution-level configurations from the Configuration Manager.

To create a new project-level configuration, you select <New…> from the Configuration dropdown for a specific project.

You then give the new configuration a name and, optionally, copy settings from an existing configuration.

By default, this will create an identically named solution-level configuration.  You can uncheck the Create new solution configurations option to avoid this.  There are cases when you don’t necessarily want a one-to-one mapping between solution-level and project-level configurations.  In the example below, we’ve created a DebugWithWarningsAsErrors option, set appropriate project properties, and then build only one project with this configuration.


#496 – Editing Solution Configurations with the Configuration Manager

You can use the Configuration Manager to view or edit solution configurations in Visual Studio 2010.

In the example below, we have a solution that contains two projects–a DogApplication project that generates an .exe (executable) and a DogLibrary project that generates a .dll (class library).  We’ve opened the Configuration Manager and selected Debug as the solution configuration and x86 as the platform.  We can see that both projects are set to use Debug as their build configuration and x86 as their platform.

We can, however, make a change so that the DogLibrary project is built using its Release configuration, even when the solution configuration is Debug.  We might do this so that we can debug the main application, but use an optimized build of the class library.

#495 – Viewing Solution Configurations with the Configuration Manager

You can edit a solution configuration by using the Configuration Manager.  You can bring up the configuration manager in several different ways.

Select it from build configuration or platform dropdowns:

From the Build menu:

Right-click the solution in Solution Explorer:

By default, the solution configuration will be mapped to corresponding build configuration and platform choices in the default child project.  For example, as you switch between Debug and Release in the solution configuration, you’ll get configurations in which the project’s build configuration is Debug or Release.

#494 – Selecting a Solution-Level Build Configuration and Platform

Visual Studio 2010 supports both solution-level and project-level build configurations.  The project-level configurations specify sets of build-related properties.  The solution-level configuration specifies which projects to build for a particular configuration, as well as the individual project-level configurations to use.

There are also both solution-level and project-level platform choices.

You can see your current solution-level build configuration and platform in the main Visual Studio 2010 toolbar.

In the example below, the current build configuration is Debug and the current platform is Any CPU.

To build your project under a different build configuration or platform, just make a new choice in one or both of these combo boxes.

In the example below, we’ve chosen to do a Release build for the x86 platform.


#493 – Project Properties Are Specific to Build Configuration and Platform

Many tabs in the project properties window include two combo boxes at the top of the tab, allowing selection of Configuration and Platform.

This window allows you to specify a set of property values for each combination of Configuration and Platform.  For example, you might have Debug and Release choices for Configuration, as well as x86 and x64 choices for Platform.  You could then specify a different value for Output path for each combination of Configuration and Platform, so that you could save four sets of binaries.

  • Debug|x86 – \bin\x86\Debug
  • Debug|x64 – \bin\x64\Debug
  • Release|x86 – \bin\x86\Release
  • Release|x64 – \bin\x64\Release

#492 – Define Your Own Conditional Compilation Symbol

You can define your own conditional compilation symbols for specific build configurations and then use the #if directive to check these symbols and conditionally compile code, depending on whether the symbol is defined or not.

For example, suppose you want to execute some debugging code only for Debug builds that are targeting the x86 platform.  You can define a new DEBUG86 symbol that is present only when the build configuration is Debug and the platform is x86.

You can then use the #if directive to compile some code only when this symbol is defined.

#if DEBUG86
            Console.WriteLine("This is a 32-bit Debug build..");