如何使用多个dll版本?
好吧,
我这里有一个奇怪的。
我们目前有一个工具应用程序,允许我们创建插件,这些插件只是带有用户控件的 DLL,我只需使用 Assembly.Load 加载并创建新实例,添加到面板即可使用。
然而,插件可能包含第 3 方 dll。
我该如何处理这个问题?
我尝试压缩插件并通过 byte[] 读取程序集,但是在尝试加载时出现错误,缺少依赖的 dll,所以我更进一步,将依赖的 dll 添加到 zip 中并读取它们,同样的错误。
也许我可以创建一个带有插件名称和依赖的 dll 的文件夹?
Alright,
I have a strange one here.
We currently have a tools application that allows us to create plugins, which are just DLLs with usercontrols, that I just load using Assembly.Load and create new instance, add to panel to use.
However a plugin could have 3rd party dlls included.
How can I handle this?
I've tried zipping up the plugin and reading the assembly via byte[], but I get an error when trying to load, missing dependant dll, so I went even farther, added dependant dlls into zip and read them, same error..
Perhaps I can create a folder with plugin name with dependant dlls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近有一个项目遇到了完全相同的问题。这是我如何解决的:
- 为每个模块(插件)创建一个单独的目录,在里面我放置了主 module.dll 库和目录 lib,其中放置了所有模块相关的库。
- 在主 Form_Load 事件中,
LoadModuleResolveEventHandler
的位置为:它使应用程序在 pluginDirectory(插件模块所在的位置)/lib 子目录中查找引用的 .dll,并且如果找到则将其返回。我在插件代码中做了类似的事情,也许你不必......就是这样。
另一种可能性是向项目添加新项目:应用程序配置文件,并将代码放在下面:
它创建 application_name.exe.config 文件,该文件必须与主窗体可执行文件一起部署,并指示在其中查找程序集解析的附加目录。
您可以将这些解决方案中的任何一个放在托盘中,看看它们是如何工作的。
谨致问候,
米杰82
I recently had a project with exactly the same problem. Here is how did I solve it:
- create a separate directory for each module (plugin), inside I put main module.dll library and directory lib, where I put all the module-dependent libraries.
- in main Form_Load event put
where
LoadModuleResolveEventHandler
is:It makes the application to look in pluginDirectory (where the plugin module is) /lib subdirectory, for a referenced .dll, and return it if found. I did similar in plugin's code, maybe you don't have to... That's it.
Other possibility is to add to the project new item: Application Configuration File, and put the code below:
It creates application_name.exe.config file which must be deploy with main form executable and indicates addicional directories where to look for assembly resolving.
You can tray any of this solutions and see how they work.
Best regards,
mj82