如何使用单个Visual Studio解决方案同时构建x86和x64? [英] How can I use a single Visual Studio solution to build both x86 and x64 at the same time?

查看:148
本文介绍了如何使用单个Visual Studio解决方案同时构建x86和x64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个x86 Visual Studio解决方案,其中包含许多项目文件.某些DLL文件旨在用作用户系统上其他应用程序的插件.

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.

我们正在扩展某些DLL文件,以便能够支持64位应用程序.我想设置解决方案/项目,以便只需按"Build" 即可构建这些DLL的x86和x64版本 文件.该解决方案包含C ++和C#项目.

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.

我认识到批处理构建"能够同时构建这两者,但是如果开发人员只需单击与以前相同的按钮并生成所有输出DLL文件,将会更加方便.

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:

我尝试将<Target Name="AfterBuild">修改为:

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

但这会导致以下错误:

C:\ Windows \ Microsoft.NET \ Framework \ v3.5 \ Microsoft.Common.targets(565,5):错误MSB4006:目标依赖关系图中涉及目标构建"的循环依赖.

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

我认为我的条件将阻止无限递归,但我了解MSBuild如何无法以这种方式看到它.

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

我也尝试过:

<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>

但是我的DefaultTargets在Visual Studio IDE中似乎被忽略了.

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>

到目前为止,这已显示出最大的希望.但是,Visual Studio似乎忽略了这个新项目中的OutputPath设置,而是将EXE/DLL文件输出到原始项目中指定的路径.我可以看到没有PropertyGroup块在原始项目中正在执行以覆盖此块,因此我不确定发生了什么.

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.

推荐答案

我们做的事情类似于为

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

尝试一下:

<Target Name="AfterBuild">
    <MSBuild Condition=" '$(Platform)' == 'x86' " Projects="$(MSBuildProjectFile)" Properties="Platform=x64;PlatFormTarget=x64" RunEachTargetSeparately="true" />
</Target>

这篇关于如何使用单个Visual Studio解决方案同时构建x86和x64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆