如何在插件方案中实现程序集绑定重定向? [英] How to achieve assembly binding redirect in a plugin scenario?

查看:81
本文介绍了如何在插件方案中实现程序集绑定重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个plugin P扩展名和一个我无法控制的application A(.NET40).
P程序集(.NET40)具有shared dependency D(.NET35).

I have a plugin P extending and application A (.NET40) that I have no control over.
The P assembly (.NET40) has a shared dependency D (.NET35).

P和D都取决于FSharp.Core,但版本不同:

Both P and D depend on FSharp.Core, but different versions:

P是针对FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
编译的 D是针对FSharp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

P is compiled against FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
D is compiled against FSharp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

仅部署了FSharp.Core版本= 4.4.0.0,我订阅了AppDomain.AssemblyResolve来加载部署的程序集.

Only FSharp.Core, Version=4.4.0.0 is deployed and I subscribe to AppDomain.AssemblyResolve to load the deployed assemblies.

虽然我正在在GAC中安装了两个FSharp.Core版本的机器上进行测试,但最终都随插件一起加载.

While I'm testing on my machine where both FSharp.Core versions are installed in the GAC, they both end up being loaded with the plugin.

我的理解是绑定重定向将是解决方案,但是如何在不访问app.config的情况下完成呢?

My understanding is that a binding redirect would be the solution here but how can it be done without access to the app.config?

推荐答案

您可以将D部署为

You could deploy D as a publisher policy assembly.

此方法的好处是客户端目录不需要包含* .config文件即可重定向到较新的版本.发布者策略允许程序集的发布者将* .config文件的二进制版本安装到GAC中(以及程序集).这样,CLR将能够在GAC级别执行请求的重定向.

The benefit of this approach is that client directories do not need to contain *.config files to redirect to a newer version. Publisher policy allows the publisher of an assembly to install a binary version of a *.config file into the GAC (along with the assembly). This way the CLR will be able to perform the requested redirection at the level of the GAC.

如果您想绕过某个应用程序的发布者政策,则可以使用<publisherPolicy>元素在应用程序的* .config文件中进行指定.

If you want to bypass the publisher policy for a certain app, you can specify so in the app’s *.config file using the <publisherPolicy> element.

<?xml version="1.0" encoding="utf-8" ?>
<configuration> 
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
            <publisherPolicy apply="no" />
        </assemblyBinding>
    </runtime> 
</configuration>

这篇关于如何在插件方案中实现程序集绑定重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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