如何使用 MSBuild 引用不同版本的 dll [英] How to reference different version of dll with MSBuild

查看:32
本文介绍了如何使用 MSBuild 引用不同版本的 dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一组 3rd 方 dll 的 Web 应用程序项目.问题是开发/登台环境是 32 位,但生产环境是 64 位.因此,我们每次要部署时都必须重新引用和构建解决方案.我现在想自动执行此操作,但不确定如何使用 MSBuild 进行操作?

I have a web application project which utilises a set of 3rd party dll's. The issue is that the dev/staging environment is 32bit, but production is 64bit. As such, we have to re-reference and build the solution each time we want to deploy. I am now wanting to automate this, but unsure how to go about it with MSBuild?

所有其他 dll 都相同,只有 3 个 3rd 方 dll.

All other dll's are the same, just the 3 3rd party dll's.

编辑

我已经取得了一些进展,但是我遇到了一些运行时程序集问题.

I have made some headway, however am coming up with some runtime assembly issues.

我有 3 个 dll 文件,1.dll、2.dll、3.dll.每个文件版本为 5.1.对于 64 位 dll,名称完全相同,只是文件版本不同.我所做的是将每个 dll 重命名为 1.v5.dll、1.v6.dll 等.在我的项目文件中,我将按如下方式引用每个 dll:

I have 3 dll files, 1.dll, 2.dll, 3.dll. The file version is 5.1 for each. For the 64 bit dlls, the names are exactly the same, just difference file versions. What I have done, is renamed each one to 1.v5.dll, 1.v6.dll etc. In my project files, I am then referencing each dll as follows:

<Reference Include="1.v5.dll" Condition="'$(Platform)'=='x86'">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>bin1.v5.dll</HintPath>
  <Private>False</Private>
</Reference>
<Reference Include="1.v6.dll" Condition="'$(Platform)'=='x64'">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>bin1.v6.dll</HintPath>
  <Private>False</Private>
</Reference>

这在 Visual Studio IDE 中有效,我的解决方案编译文件,但是当我去运行网站时,我收到以下错误...

This works in Visual Studio IDE, and my solution compiles file, however when I go to run the website, I get the following error...

无法加载文件或程序集1.v5"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.

"Could not load file or assembly '1.v5' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

对如何解决这个问题有任何想法吗?

Any thoughts on how to approach this?

推荐答案

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

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.

这篇关于如何使用 MSBuild 引用不同版本的 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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