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

查看:27
本文介绍了如何使用单个 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"> 来尝试:

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>

但这会导致以下错误:

C:WindowsMicrosoft.NETFrameworkv3.5Microsoft.Common.targets(565,5): error MSB4006: 在涉及目标Build"的目标依赖图中存在循环依赖.

C:WindowsMicrosoft.NETFrameworkv3.5Microsoft.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.

推荐答案

我们做了一些类似的事情来为 .NET Compact Framework.

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天全站免登陆