[英]App.config runtime probing with wildcard or recursive
我正在尝试通过<probing>
元素加载 dll。 我有一个文件夹结构,它由插件内的几个插件文件夹组成。 所以我正在寻找一种方法来递归地遍历所有这些插件文件夹以找到 dll。
这是我的文件夹结构:
这就是我的 App.config 的样子,但它似乎没有抓住plugins\\*
部分。
<?xml version="1.0" encoding="utf-8">
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="MyApplication;plugins;plugins\*;"/>
</assemblyBinding>
</runtime>
</configuration>
如果我让它像: <probing privatePath="MyApplication;plugins;plugins\\fooplugin;">
它会找到 foo.dll。 但我不确定会出现哪些插件。
使用probing
元素时不能使用通配符搜索。 相反,您需要将 DLL 复制到共享文件夹中或指定它们可能存在的每个文件夹。
如果您的插件是由其他项目生成的,您可以将它们设置为直接构建到您的插件文件夹,或者最好在MyApplication
项目中有一个后期构建任务,将文件复制到您的项目插件文件夹中。
通过处理AppDomain.CurrentDomain.AssemblyResolve
事件,您可以轻松地做您想做的事。
然后在附加的事件处理程序中调用:
Assembly assembly = Assembly.LoadFile(path: assemblyPath); return assembly; // return resolved assembly
assemblyPath
是程序试图获取的 DLL 的绝对路径,您可以通过在运行时扫描 DLL 文件夹然后获取包含缺少的 DLL 名称的路径来获取该路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.