这是我的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
</configuration>
我引用的DLL设置为不复制到本地,我已经将DLL复制到调试文件夹中的lib目录,它运行良好,但是当我将程序与我的库文件夹一起移动时,它并没有&#39工作。
当程序和库目录到另一个文件夹时,有没有办法让它工作?
答案 0 :(得分:0)
这有点晚了,但是还有另一种方法,将其添加到您的Main方法中
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;
创建方法
private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
AssemblyName assyName = new AssemblyName(args.Name);
string filename = args.Name.ToLower().Split(',')[0];
string path = "c:\some path or other\"
string assembly = System.IO.Path.Combine(path, filename);
if (!assembly.EndsWith(".dll"))
assembly += ".dll";
try
{
if (System.IO.File.Exists(assembly))
return (Assembly.LoadFrom(assembly));
}
catch (Exception error)
{
// do whatever
}
return (null);
}