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

发布于 2024-08-25 14:52:28 字数 351 浏览 7 评论 0原文

我有以下情况

项目 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

口干舌燥 2024-09-01 14:52:28

我使用以下配置来解决该问题。

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Castle.DynamicProxy2" publicKeyToken="407dd0808d44fbdc" />
                <codeBase version="2.1.0.0" href="v2.1\Castle.DynamicProxy2.dll" />
                <codeBase version="2.2.0.0" href="v2.2\Castle.DynamicProxy2.dll" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />
                <codeBase version="1.1.0.0" href="v2.1\Castle.Core.dll" />
                <codeBase version="1.2.0.0" href="v2.2\Castle.Core.dll" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

I used the following configuration to resolve the issue.

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Castle.DynamicProxy2" publicKeyToken="407dd0808d44fbdc" />
                <codeBase version="2.1.0.0" href="v2.1\Castle.DynamicProxy2.dll" />
                <codeBase version="2.2.0.0" href="v2.2\Castle.DynamicProxy2.dll" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />
                <codeBase version="1.1.0.0" href="v2.1\Castle.Core.dll" />
                <codeBase version="1.2.0.0" href="v2.2\Castle.Core.dll" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
牵强ㄟ 2024-09-01 14:52:28

一件非常非常重要的事情,如果不给予足够的关注,人们可能会错过这一点。

您在 codeBase 版本标记中编写的程序集必须强命名。

通过以下链接: http://msdn.microsoft.com/en-us/库/efs781xb.aspx

对于没有强名称的程序集,版本将被忽略,并且
loader 使用的第一次出现里面
<依赖程序集>。如果应用程序中有一个条目
将绑定重定向到另一个程序集的配置文件,
即使程序集版本没有,重定向也会优先
匹配绑定请求。

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

For assemblies without a strong name, version is ignored and the
loader uses the first appearance of <codebase> inside
<dependentAssembly>. If there is an entry in the application
configuration file that redirects binding to another assembly, the
redirection will take precedence even if the assembly version doesnt
match the binding request.

仅此而已 2024-09-01 14:52:28

一种解决方案(或解决方法)是在需要运行软件的计算机上的全局程序集缓存 (GAC) 中安装这两个版本,并使用其强名称引用程序集。这假设程序集确实具有强名称。

如果您有多个开发人员或者您计划将您的解决方案部署到许多计算机(例如作为最终用户应用程序),那么安装到 GAC 中将会很痛苦。在这种情况下,我相信(但我可能是错的)您唯一的选择是将两个版本之一合并到需要该版本的程序集中。在您的具体情况下,您需要将 Castle.DynamicProxy2.dll v2.1 合并到 NHibernate.dll 中。

您可以使用名为 ILMerge 的工具来合并程序集。您需要运行的命令如下所示(未经测试):

ILMerge /t:library /internalize /out:Deploy/NHibernate.dll
    NHibernate.dll Castle.DynamicProxy2.dll

/internalize 开关告诉 ILMerge 标记第二个程序集(本例中为 Castle)internal 中的所有类型在输出组件中。如果没有这个,当您尝试编译引用新的 NHibernate.dllCastle.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 into NHibernate.dll.

You can use a tool called ILMerge to merge the assemblies. The command you will need to run looks something like this (untested):

ILMerge /t:library /internalize /out:Deploy/NHibernate.dll
    NHibernate.dll Castle.DynamicProxy2.dll

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 new NHibernate.dll and the shelf version of Castle.DynamicProxy2.dll v2.2, as they will contain classes with the exact same names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文