加载同一程序集的多个版本 [英] Loading multiple versions of the same assembly

查看:314
本文介绍了加载同一程序集的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与第三方组装工作,不幸的是我现在需要加载他们的最新和previous版本到我的项目,所以在运行时我可以决定要加载哪一个。我只需要一个,不能同时使用。

I'm working with a third-party assembly and unfortunately I now need to load their latest and a previous version into my project so at runtime I can decide which one to load. I only ever need one, not both.

考虑到这一点,我也取决于由组件提供的类型,所以我不能从反射加载和查询,我要使用的方法/事件/接口每次。我已经通过看到处理该部分提及的AppDomain 取值但我不知道怎么办。

With this in mind, I am also dependent upon the types provided by the components so I cannot load from reflection and query every time for the method/events/interfaces that I want to use. I have seen some mention of handling this via AppDomains but am not sure how to proceed.

会过程是code对部件的一个版本,然后在运行时(使用应用程序域)中的正确的DLL交换欲食用?所以我只在启动时处理这?

Would the process be to code against one version of the component and then at run-time (using the AppDomain) swap in the correct DLL I want to be consumed? So I would only be handling this at startup?

推荐答案

如果这两个组件是兼容的,你可以在app.exe.config或web.config文件,通过声明bindingRedirect总是使用新版本定义。

If both assemblies are compatible you can define in the app.exe.config or web.config file to always use the new version by declaring bindingRedirect .

例如

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705">
        <dependentAssembly>
            <assemblyIdentity name="Regcode" publicKeyToken="b03f5f7f11d50a3a" culture=""/>
            <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/>
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

有关DOTNET 1.0本config条目告诉asembly装载机总是不管使用版本1.0.3300.0什么被编译到调用exe文件。同样是可能的较新版本的DOTNET

this config entry for dotnet 1.0 tells the asembly loader always to use version 1.0.3300.0 no matter what is compiled into the calling exe. The same is possible with newer dotnet versions

这篇关于加载同一程序集的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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