且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 MSBuild 引用不同版本的 dll

更新时间:2023-01-10 10:30:27

这是我想出来的,似乎没有问题.

This is what I have figured out, and seems to work no problems.

我创建了 2 个解决方案平台,x86x64.我在我的解决方案目录中创建了一个名为References"的新文件夹,并创建了 n 个 x86 和 x64 文件夹:参考x86\参考x64然后将每个的 3 个 dll 放在各自的目录中.

I have created 2 solution platforms, x86 and x64. I have created a new folder in my solution directory called "References", and created n x86 and x64 folder: Referencesx86 Referencesx64 The 3 dll's for each are then placed in their respective directories.

在每个项目的文件中,我添加了以下引用:

In each project's file, I have then added the following references:

<Reference Include="{Reference1}" Condition="'$(Platform)'=='x86'">
  <HintPath>..Referencesdllsx86{Reference1}.dll</HintPath>
</Reference>
<Reference Include="{Reference2}" Condition="'$(Platform)'=='x64'">
  <HintPath>..Referencesdllsx64{Reference2}.dll</HintPath>
</Reference>

现在,当我在 IDE 中进行开发时,我正在处理特定于我需要的相关 dll.

Now, when I develop within the IDE, I am working the the relevant dll specific to my needs.

然后我刚刚添加了一个构建后事件,该事件将基于 $(Platform) 变量的 dll 复制到 bin 目录中.

I have then just added a post-build event which copies the dll based on the $(Platform) variable into the bin directory.