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

查看:104
本文介绍了建议使用具有不同版本的依赖项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天全站免登陆