使用一个单一的Visual Studio解决方案,同时建立x86和x64的?解决方案、Studio、Visual

2023-09-07 22:16:05 作者:非买品

我有一个x86的Visual Studio解决方案,在这众多的项目文件。一些dll的设计工作,作为插件在用户的系统中其他应用程序。我们正在扩大的一些dll的是能够支持64位应用程序。我想要做的是设置的解决方案/项目,使刚刚打建将建设两个x86和x64这些DLL版本。该解决方案包含C ++和C#项目。我认识到,批生成有能力建造两个,但如果开发人员可以直接点击相同的按钮,因为他们有previously,并拥有所有产生的输出的DLL会比较方便。

下面是一对夫妇,我已经试图测试项目的修改,但还没有得到工作:

我试着修改<目标名称=AfterBuild> 来试试:

 <目标名称=AfterBuild条件='$(平台)'=='86'>
  <的PropertyGroup>
    <平台> 64< /平台>
    < PlatformTarget> 64< / PlatformTarget>
  < /的PropertyGroup>
  < CallTarget目标=生成/>
< /目标>
 

但导致以下错误:

 C:\ WINDOWS \ Microsoft.NET \框架\器v3.5 \ Microsoft.Common.targets(565,5):错误MSB4006:有一个循环依赖于目标依赖关系图中涉及的目标打造 
Visual Studio如何同一个解决方案建两个项目

我觉得我的条件将prevent无限递归,但我了解的MSBuild不能这样认为。

我也试过:

 <项目DefaultTargets =MyBuild86; MyBuild64的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003ToolsVersion =3.5>
...
<目标名称=MyBuild86>
  <的PropertyGroup>
    <平台> 86< /平台>
    < PlatformTarget> 86< / PlatformTarget>
  < /的PropertyGroup>
  < CallTarget目标=生成/>
< /目标>
<目标名称=MyBuild64>
  <的PropertyGroup>
    <平台> 64< /平台>
    < PlatformTarget> 64< / PlatformTarget>
  < /的PropertyGroup>
  < CallTarget目标=生成/>
< /目标>
 

但我的 DefaultTargets 似乎从Visual Studio IDE中忽略了。

最后,我尝试创建导入的第一个项目一个单独的项目:

 < XML版本=1.0编码=UTF-8&GT?;
<项目ToolsVersion =3.5DefaultTargets =生成的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003>
  <的PropertyGroup>
    <结构状态='$(配置)'==''>调试和LT; /结构>
    <平台> 64< /平台>
    < PlatformTarget> 64< / PlatformTarget>
    <的ProductVersion> 9.0.30729< /的ProductVersion>
    < SchemaVersion> 2.0< / SchemaVersion>
    < OutputPath> .. \ $(配置)\ 64 \< / OutputPath>
    < ProjectGuid> {A885CAC3-2BBE-4808-B470-5B8D482CFF0A}< / ProjectGuid>
  < /的PropertyGroup>
  <导入项目=BuildTest.csproj/>
< /项目>
 

和这个迄今为止所表现出来的最有希望。但是,Visual Studio中似乎忽略我 OutputPath 从这个新的项目设置,而是输出EXE / DLL到原来的项目指定的路径。有没有的PropertyGroup 块,我可以看到在原来的项目来覆盖这个执行,所以我不知道发生了什么。

解决方案

我们做同样打造核心组件的.NET CF的东西 试试这个:

 <目标名称=AfterBuild>
    < MSBuild的条件='$(平台)'=='86'项目=$(MSBuildProjectFile)属性=平台= 64; PlatFormTarget = 64RunEachTargetSeparately =真/>
< /目标>
 

I've got an x86 Visual Studio solution with many project files in it. Some of the DLLs are designed to work as plug-ins to other applications on a user's system. We're expanding some of the DLLs to be able to support 64-bit applications. What I'd like to do is setup the solution/projects so that just hitting "Build" will build both the x86 and x64 versions of those DLLs. 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 DLLs generated.

Here's a couple of the modifications that I've tried to a test project, but 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 to the path specified in the original project. There's no 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 CF. Try this:

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