简体   繁体   中英

Reference a project in Visual Studio and build it for a specific platform

I have a project A which is supposed to be built for x86 and it depends on another project B which is built for x64. I can build it as it is of course but I would like no runtime issues.

So the idea is for me to set project A up so that if I want to build it for x86 I can reference project B but have it built for x86 and if I want to build project A for x64 then I reference project B but have it built for x64. Is this possible?

I put a condition in the.csproj of Project A like:

<ItemGroup Condition=" '$(Platform)' == 'x86' ">

    <ProjectReference Include="..\Project B\projB.csproj">
      <Project>{678c5dc7-7a1c-45g3-bffe-a4754c64f027}</Project>
      <Name>projB</Name>
    </ProjectReference>
</ItemGroup>

<!-- x64 specific referneces -->
<ItemGroup Condition=" '$(Platform)' == 'x64' ">

    <ProjectReference Include="..\Project B\projB.csproj">
      <Project>{678c5dc7-7a1c-45g3-bffe-a4754c64f027}</Project>
      <Name>projB</Name>
    </ProjectReference>
</ItemGroup>

But I don't know how to have that referenced project build for a specific platform. I know I could just take the.dlls of the two versions and apply a condition for normal references but wanted to see if this is viable. Is it possible? Would I need two separate identical projects but with different target platforms to do this?

Would appreciate if you could help me, thanks!

Reference a project in Visual Studio and build it for a specific platform

Project Reference is quite different. And What you provide is to build a project on different platforms based on project A . Project B will not use the corresponding version of platform to build Project B according to the platform change in A .

And Project Reference is actually to build project B first and then build project A , Reference the corresponding Project B . It needs to be configured again.

Update

In your situation, when build project A, it has a condition like Condition=" '$(Platform)' == 'x86' " , it is only based on the current platform of project A, but this parameter cannot be passed to project B to compile the project as x86 . So you should

Therefore , you need to manually change the platform of B to achieve your goal.

Solution

1) Build --> Configuration Manager and change like these to build your project.

在此处输入图像描述

or

在此处输入图像描述

2) When you build Porject A with x86 , you should first change Project B to x86 platform and when you do the same with x64 , you should also do the same operation to Project B.

Right-click on your project A and B--> Properties --> Build --> change Platform target to both x64 or x86.

And then you can get the same platform output file in project A ouputpath folder.

In addition , you can try to build Project B based on x64 , x86 platform at the same time(could refer to this link ) and then use like your xml code in Project A(according to x64 or x86 platform) to reference(assembly reference) the corresponding project B.dll.

Hope it could help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM