原文:
关于指定dll搜索路径
问题现象
当部分DLL放在子文件夹下,需要指定DLL搜索路径,否则系统将找不到文件
产生原因
系统默认搜索只会在前程序目录并不包括子目录
解决方法
1,使用App.config配置实现,但该方法有局限性,只能在EXE项目下配置
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins"/>
</assemblyBinding>
</runtime>
</configuration>
2,在AppDomain.AppendPrivatePath中配置,该方法在任何地方都可使用
AppDomain.CurrentDomain.AppendPrivatePath("plugins");