Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a single Visual Studio solution to build both x86 and x64 at the same time?

I've got an x86 Visual Studio solution with many project files in it. Some of the DLL files are designed to work as plug-ins to other applications on a user's system.

We're expanding some of the DLL files to be able to support 64-bit applications. I'd like to set up the solution/projects so that just hitting "Build" will build both the x86 and x64 versions of those DLL files. The solution contains both C++ and C# projects.

I realize that "Batch Build" is capable of building both, though it would be more convenient if developers could just click the same button as they have previously and have all of the output DLL files generated.

Here are a couple of the modifications that I've tried to a test project, but that I haven't gotten to work:

I've tried modifying the <Target Name="AfterBuild"> to try:

<Target Name="AfterBuild" Condition=" '$(Platform)' == 'x86' ">   <PropertyGroup>     <Platform>x64</Platform>     <PlatformTarget>x64</PlatformTarget>   </PropertyGroup>   <CallTarget Targets="Build"/> </Target> 

But that results in the following error:

C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(565,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "Build".

I think my conditions will prevent infinite recursion, but I understand how MSBuild could not see it that way.

I've also tried:

<Project DefaultTargets="MyBuild86;MyBuild64" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> ... <Target Name="MyBuild86">   <PropertyGroup>     <Platform>x86</Platform>     <PlatformTarget>x86</PlatformTarget>   </PropertyGroup>   <CallTarget Targets="Build"/> </Target> <Target Name="MyBuild64">   <PropertyGroup>     <Platform>x64</Platform>     <PlatformTarget>x64</PlatformTarget>   </PropertyGroup>   <CallTarget Targets="Build"/> </Target> 

But my DefaultTargets appears to be ignored from within the Visual Studio IDE.

Last, I've tried creating a separate project that imports the first project:

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <PropertyGroup>     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>     <Platform>x64</Platform>     <PlatformTarget>x64</PlatformTarget>     <ProductVersion>9.0.30729</ProductVersion>     <SchemaVersion>2.0</SchemaVersion>     <OutputPath>..\$(Configuration)\x64\</OutputPath>     <ProjectGuid>{A885CAC3-2BBE-4808-B470-5B8D482CFF0A}</ProjectGuid>   </PropertyGroup>   <Import Project="BuildTest.csproj" /> </Project> 

And this so far has shown the most promise. However, Visual Studio seems to ignore my OutputPath setting from this new project and instead outputs the EXE/DLL file to the path specified in the original project. There isn't any PropertyGroup block that I can see that is being executed in the original project to override this, so I'm not sure what's happening.

like image 925
PeteVasi Avatar asked Oct 15 '09 18:10

PeteVasi


People also ask

Do I need both x86 and x64 Visual C++?

In most cases you should install both the x64 (64-bit) and the x86 (32-bit) versions. If you're using a 32-bit version of Windows, then you only need to install the x86 version.

How do I add x86 to Visual Studio?

Click TOOLS > SETTINGS > check EXPERT SETTINGS to see the build configuration manager (This is only applicable to Visual Studio 2010 Express Edition and NOT for 2008 Express Edition) Click BUILD > CONFIGURATION MANAGER select the platform dropdown to X86 and click CLOSE.

How do I change a platform target to x86 in Visual Studio?

Click Configuration Manager. In the Configuration Manager dialog, open the Active solution platform drop-down list box and click <New> …. In the New Solution Platform dialog, select x64 in the Type or select the new platform drop-down list box. Select x86 in the Copy settings from drop-down list box.

How do I know if I have Visual Studio x64 or x86?

The easiest way, without installing another program or running the file, is just to right click on the file, choose Properties, and then go the the Compatibility tab. If there are no greyed out options and Windows XP and 9x modes are offered, it's 32-bit.

How to build x86 and x64 versions of a vcproj project?

Voriel is right: use batch build to build both configurations. Alternatively you could create two vcproj files in your solution -- one for x86 and the other for x64 and add the same source files to them. Unfortunately it causes a maintenance headache as any project settings need to be duplicated for each project.

How do I build a project only in Visual Studio C++?

Choose a Visual C++ project, and then, on the menu bar, choose Build > Project Only, and one of the following commands: These commands apply only to the Visual C++ project that you chose, without building, rebuilding, cleaning, or linking any project dependencies or solution files.

What is a Visual Studio solution?

If you're a .NET developer you probably use or have used Visual Studio. Visual Studio has two kinds of project organization file formats: projects and solutions. Solutions are essentially groups of projects.

Can We have both C #and Visual Basic project in same solution?

Can we have both c# and visual basic project in same solution ?. The response I used to received “No, it is not possible”, “Yes. we can do it for web project” etc. This question comes up when we discuss about very basic of CLS, CTS, MSIL etc.


1 Answers

We do something similar to build core assemblies for .NET Compact Framework.

Try this:

<Target Name="AfterBuild">     <MSBuild Condition=" '$(Platform)' == 'x86' " Projects="$(MSBuildProjectFile)" Properties="Platform=x64;PlatFormTarget=x64" RunEachTargetSeparately="true" /> </Target> 
like image 116
Todd Avatar answered Sep 27 '22 00:09

Todd