您能否建议从特定位置加载.NET程序集?我有以下限制:
答案 0 :(得分:0)
要从特定位置选择程序集,请将这些程序集添加到App.Config文件
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="resources"/>
</assemblyBinding>
</runtime>
此处“资源”是自定义文件夹。您可以在此文件夹中添加dll。每次你的应用程序启动时,它会首先在这个自定义文件夹中查找dll,你可以根据需要将其命名为任何内容
答案 1 :(得分:0)
我做了以下假设:
您是否尝试过使用Assembly.LoadFrom
method?您应该可以通过以下方式获取插件库位置:
Assembly me = System.Reflection.Assembly.GetExecutingAssembly();
// Get the file path of the currently running assembly
string pathToMe = me.Location;
string pluginFolder = System.IO.Path.GetDirectoryName(pathToMe);
然后,您应该能够加载其他程序集,假设它位于同一文件夹中。
答案 2 :(得分:0)
您可以使用AppDomain.AssemblyResolve
事件在运行时以编程方式从自定义位置加载程序集。
由于您无法控制加载插件的实际应用程序,因此这依赖于应用程序以某种方式执行您的某些代码,以便您有机会挂钩AppDomain
。
由于您还没有详细了解您正在使用的插件架构,因此很难知道这是否适合您。