C#程序从指定路径或网络加载引用的DLL
1.在App.config 配置文件 中runtime节点下,添加privatePath属性来添加指定目录,只能填写相对路径:
-
<runtime>
-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
-
//程序集当前目录下的相对路径目录,多个相对路径用;号分割
-
<probing privatePath="目录1;目录2;" />
-
</assemblyBinding>
-
</runtime>
html
2.如果程序集是强签名后的,那么可以通过codeBase来指定网络路径或本地绝对路径。
-
<runtime>
-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
-
<dependentAssembly>
-
<assemblyIdentity name="myAssembly"
-
publicKeyToken="32ab4ba45e0a69a1"
-
culture="neutral" />
-
<codeBase version="2.0.0.0"
-
href="http://www.litwareinc.com/myAssembly.dll" />
-
</dependentAssembly>
-
</assemblyBinding>
-
</runtime>
html
当然,我们还可以在代码中通过AppDomain 类 中的几个成员来改变搜索规则,如AssemblyResolve事件、AppDomainSetup类等。
有关运行时节点的描述:https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/runtime/runtime-element
2026-08-17 11:36:10【出处】:https://blog.csdn.net/zhaijingkui/article/details/83652952
=======================================================================================
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【关注我】。(●'◡'●)
因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/22516966
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
浙公网安备 33010602011771号