运行具有不同版本的依赖项 dll 的插件的推荐方法是什么? [英] What's the recommended way to run plugins with dependency dll's that have different version?

查看:28
本文介绍了运行具有不同版本的依赖项 dll 的插件的推荐方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 插件服务,它通过 MEF 加载插件并运行它们.

I have a WCF plugin service that loads plugins via MEF and runs them.

每个插件都是一个目录,其中包含多个实现特定接口的 dll.

Each plugin is a directory with multiple dll's that implements a specific interface.

我使用 MEF (DirectoryCatalog) 在同一个 AppDomain 中加载所有插件并以通用方式运行它们(使用反射).

I load all the plugins in the same AppDomain using MEF (DirectoryCatalog) and run them in a generic way (using reflection).

现在假设我有两个具有 dll 依赖项的插件:

Now lets assume I have two plugins with dll dependencies:

Plugin1
     ----> Entities 1.0.0.1

Plugin2
     ----> Entities 1.0.0.2

我在 1.0.0.2 中添加了一些新实体.

I've added some new entities in 1.0.0.2.

当我运行插件时,我收到一个偶发错误,新实体不存在于 dll 中.

When I run the plugin's I get a sporadic error that the new entities doesn't exist in the dll.

我猜是因为我在同一个 AppDomain 中运行代码,并且加载的第一个 Entities.dll 是为我的所有插件提供服务的那个.

I guess that the error occurs since I'm running the code in the same AppDomain and the first Entities.dll that loads is the one that will serve all my plugins.

那么,如何在不创建新应用域的情况下独立运行每个插件?

So, how can I run each plugin with isolation, without creating a new appdomain?

有什么办法可以告诉 MEF 以某种方式加载所有插件依赖项吗?

Is there any way I can tell MEF to load all plugin dependencies somehow?

我在网上阅读了一些解决方案:

I've read about a couple of solutions on the web:

  1. 为每个插件创建一个新的应用程序域 - 我不想去那里.

使用 <dependentAssembly> - 当我第一次尝试它时这不起作用,我不希望我的插件服务器在每个程序集依赖版本更改时更新.另外,我希望能够运行具有不同程序集版本的插件.

Use the <dependentAssembly> - This didn't work when I first tried it and I don't want my plugin server to get updated on each assembly dependency version change. Plus, I want to be able to run plugins with different assembly versions.

使用 snk 对程序集进行签名 - 我还没有尝试过,我不确定这个解决方案是否有效.框架如何知道他需要加载不同的程序集?这与不同版本的程序集有何不同?我是否需要以某种方式配置我的服务才能使其正常工作?

Sign the assemblies with a snk - I didn't try this yet and I'm not sure this solution will work. How will the framework know that he needs to load a different assembly? How is this different from assemblies with different versions? Will I need to configure my service somehow in order to make this work?

有人对我有更好的主意吗?运行独立插件的推荐方式是什么?

Does anybody have any better idea for me? What's the recommended way to run isolated plugins?

推荐答案

您需要对程序集进行签名并确保每个程序集的程序集版本都不同.从下面看答案:C#加载不同同一项目的程序集版本

You need to sign your assemblies And make sure the assembly version is different on each one. See the answer from the following: C# Load different versions of assembly to the same project

CLR 确实支持将多个版本的强命名程序集加载到同一个 AppDomain 中.不过,这仅在您的程序集具有强名称且每个程序集的版本都不同时才有效.

The CLR does support loading multiple versions of strongly named assemblies into the same AppDomain. This only works though if your assemblies are strongly named and each one has a different version than the other.

这篇关于运行具有不同版本的依赖项 dll 的插件的推荐方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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