在同一文件夹中使用同一程序集的不同版本

我有以下情况


项目A.


 - Uses Castle Windsor v2.2

 - Uses Project B via WindsorContainer

项目B.


 - Uses NHibernate

 - Uses Castle Windsor v2.1

在Project AI的bin文件夹中有dll Castle.DynamicProxy2.dll v2.2和NHibernate dll。现在问题是NHibernate依赖于Castle.DynamicProxy2.dll v2.1而不存在。我该如何解决这种情况。


桃花长相依
浏览 566回答 3
3回答

慕娘9325324

我使用以下配置来解决此问题。<configuration>&nbsp; &nbsp; <runtime>&nbsp; &nbsp; &nbsp; &nbsp; <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <dependentAssembly>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <assemblyIdentity name="Castle.DynamicProxy2" publicKeyToken="407dd0808d44fbdc" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <codeBase version="2.1.0.0" href="v2.1\Castle.DynamicProxy2.dll" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <codeBase version="2.2.0.0" href="v2.2\Castle.DynamicProxy2.dll" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dependentAssembly>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <dependentAssembly>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <codeBase version="1.1.0.0" href="v2.1\Castle.Core.dll" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <codeBase version="1.2.0.0" href="v2.2\Castle.Core.dll" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dependentAssembly>&nbsp; &nbsp; &nbsp; &nbsp; </assemblyBinding>&nbsp; &nbsp; </runtime></configuration>

互换的青春

一种解决方案(或解决方法)是在您的软件需要运行的机器上的全局程序集缓存(GAC)中安装这两个版本,并使用其强名称引用程序集。这假设程序集确实具有强名称。如果您有多个开发人员,或者您计划将解决方案部署到许多计算机(例如,作为最终用户应用程序),那么安装到GAC将是一件痛苦的事。在这种情况下,我相信(但我可能错了)你唯一的选择是将两个版本中的一个合并到需要该版本的程序集中。在您的特定情况下,您需要Castle.DynamicProxy2.dll合并到v2.1 NHibernate.dll。您可以使用名为ILMerge的工具合并程序集。您需要运行的命令看起来像这样(未经测试):ILMerge /t:library /internalize /out:Deploy/NHibernate.dll&nbsp; &nbsp; NHibernate.dll Castle.DynamicProxy2.dll该/internalize开关告诉ILMerge internal在输出程序集中标记来自第二个程序集(在本例中为Castle)的所有类型。如果没有这个,当您尝试编译引用v2.2的新NHibernate.dll版本和Castle.DynamicProxy2.dll架构版本的项目时,可能会遇到编译错误,因为它们将包含具有完全相同名称的类。
打开App,查看更多内容
随时随地看视频慕课网APP