C# – Visual Studio: How to properly build and specify the configurations and platforms for x64 and x86

64-bitbuildcvisual studio 2012x86

Using: Visual Studio 2012 Professional and Ultimate with all latest updates

How do I properly specify the configuration and platform to properly build x86 and x64.

Visual Studio, when you first create a Winforms application gives you two configurations, Debug and Release, with AnyCPU defined as the platform.

If you just target one platform, then the answer is easy, you go to the Build | Configuration Manager and select one of the platforms and then go to the project properties' build page and select the same platform (x86 or x64) and voila! You wind up with (say you want x86)

/bin/x86/Debug
/bin/x86/Release

I have a solution with one application and multiple dependency projects (DLL assemblies).

Since the VS Configuration Manager has two dropdown lists at the top, Configuration and Platform and then on the project level another configuration and platform, I did the following:

(Before typing further, I think the whole setup sucks, but…)

I created two new configurations Debug64 and Release64 using the top most dropdown and selected Mixed Platforms for the platform.

I selected each of the four main solution configurations in turn and then set the project level configuration and project level platform to match, so:

Debug64 === Debug64, x64
Release64 === Release64, x64
Debug === Debug, x86
Release === Release, x86

I then went into the project properties (Alt + Enter) build page, ignored the platform and selected each configuration in turn and then set the target processor to match. I changed the output to be the following:

Debug64: /bin/x64/Debug
Release64: /bin/x64/Release
Debug: /bin/x86/Debug
Release: /bin/x86/Release

By default, Visual Studio uses the top platform to set the folder and the configuration name to set the last part of the output. If I save and close out of the project properties, then all seems fine. I can build, and wind up with the proper folders.

The problem comes, when I switch solution configurations on the Visual Studio toolbar. The project properties build page reverts back to what it wants by default, namely, say, /bin/x64/Debug64 for both debugs and something similar for the release.

What prompted me to write this issue is that the designer gets confused and cannot find the appropriate library.

I would like to select from the Visual Studio solution configuration dropdown my desired target (Debug x64, Release x64, Debug x86, Release x86) and have it build.

How do I do that? What am I doing wrong?

Creating just two solution configurations, Debug and Release, does not work, because there is no solution platform dropdown, which then targets all sub-projects. Visual Studio has, it seems to me, way too many configurations sections and platform sections. Maybe I am just missing something.

Best Answer

For posterity, here is the answer. It may sound obvious, but it was not to me, so...

Notes: Creating Debug64 and Release64 were mistakes that cost me. I not only had to remove the Debug64 and Release64 present in the solutions (in Configuration Manager), but I had to delete the automatically generated Debug64 and Release64 for each of the projects (also in Configuration Manager, just in the table part). That took a while.

  1. Make sure that you have the automatically generated debug and release solution configurations.

  2. In the solution platforms add in x86 and x64. The default is Any CPU.

  3. Select from the solution configuration and platform dropdowns the various permutations of (Debug/Release and x86/x64). Make sure the projects match, which they should.

  4. Go into each project (select project name and then Alt+Enter).

  5. In the project properties page, select the various permutations of Debug/Release and x86/x64 in the solution dropdowns. Make sure the target processor is set correctly (it should be, but I found instances when they were not, probably because of my previous attempts). Also, set the output directory. That should be okay and automatic (/bin/x86/Debug, etc.). If not, fix.

Microsoft does not have a solution platform dropdown in the toolbar, so if you want to change solution platforms, then you must go to the Build | Configuration Manager and select the appropriate solution platform. You can select the solution configuration either from the Build | Configuration Manager (Visual Studio will automatically update the selected solution configuration in the toolbar dropdown) or simply select the new solution configuration in the Visual Studio dropdown.

Building the project will take care of the rest.

Build Notes 1. The Visual Studio designer requires x86 versions of user controls in order to display properly. That was not obvious at the onset, but is now. Visual Studio installs to the "C:\Program Files (x86)" folder and not the "C:\Program Files" folder, making Visual Studio a 32-bit application, not a 64-bit one, hence its ability to "use" only 32-bit versions in the designer.

  1. There might be stray /bin/Debug and /bin/release folders, but they will not be used.

  2. I am still trying to get BuildVersionInc to not increment when building the same code through on different configurations, but that is a different issue.