在同一文件夹中使用同一程序集的不同版本
我有以下情况
项目 A
- Uses Castle Windsor v2.2
- Uses Project B via WindsorContainer
项目 B
- Uses NHibernate
- Uses Castle Windsor v2.1
在项目 AI 的 bin 文件夹中,有 dll Castle.DynamicProxy2.dll v2.2 和 NHibernate dll。现在的问题是NHibernate依赖于Castle.DynamicProxy2.dll v2.1,但它不存在。我该如何解决这种情况。
I have the following situation
Project A
- Uses Castle Windsor v2.2
- Uses Project B via WindsorContainer
Project B
- Uses NHibernate
- Uses Castle Windsor v2.1
In the bin folder of Project A I have the dll Castle.DynamicProxy2.dll v2.2 and NHibernate dlls. Now the problem is that NHibernate is dependent on Castle.DynamicProxy2.dll v2.1 which is not there. How do I resolve this situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用以下配置来解决该问题。
I used the following configuration to resolve the issue.
一件非常非常重要的事情,如果不给予足够的关注,人们可能会错过这一点。
您在 codeBase 版本标记中编写的程序集必须强命名。
通过以下链接: http://msdn.microsoft.com/en-us/库/efs781xb.aspx
One thing very, very, very important that one might miss if he is not paying enough attention.
The assembly you write in the codeBase version tag, must be strong named.
From the following link: http://msdn.microsoft.com/en-us/library/efs781xb.aspx
一种解决方案(或解决方法)是在需要运行软件的计算机上的全局程序集缓存 (GAC) 中安装这两个版本,并使用其强名称引用程序集。这假设程序集确实具有强名称。
如果您有多个开发人员或者您计划将您的解决方案部署到许多计算机(例如作为最终用户应用程序),那么安装到 GAC 中将会很痛苦。在这种情况下,我相信(但我可能是错的)您唯一的选择是将两个版本之一合并到需要该版本的程序集中。在您的具体情况下,您需要将
Castle.DynamicProxy2.dll
v2.1 合并到NHibernate.dll
中。您可以使用名为 ILMerge 的工具来合并程序集。您需要运行的命令如下所示(未经测试):
/internalize
开关告诉 ILMerge 标记第二个程序集(本例中为 Castle)internal
中的所有类型在输出组件中。如果没有这个,当您尝试编译引用新的NHibernate.dll
和Castle.DynamicProxy2.dll
v2.2 的现成版本的项目时,可能会出现编译错误,因为它们将包含具有完全相同名称的类。One solution (or workaround) would be to install both versions in the Global Assembly Cache (GAC) on the machine(s) on which your software needs to run, and reference the assemblies using their strong names. This assumes that the assemblies do indeed have strong names.
Installing into the GAC will be a pain if you have more than a few developers or if you plan to deploy your solution to many computers (eg as an end-user application). In this case, I believe (but I might be wrong) that your only option is to merge one of the two versions into the assembly requiring that version. In your specific case, you need
Castle.DynamicProxy2.dll
v2.1 to be merged intoNHibernate.dll
.You can use a tool called ILMerge to merge the assemblies. The command you will need to run looks something like this (untested):
The
/internalize
switch tells ILMerge to mark all types from the second assembly (Castle in this case)internal
in the output assembly. Without this, you might get compile errors when you try to compile a project referencing both your newNHibernate.dll
and the shelf version ofCastle.DynamicProxy2.dll
v2.2, as they will contain classes with the exact same names.