加载来自不同文件夹中的DLL的参考? [英] load a DLL reference from a different folder?

查看:336
本文介绍了加载来自不同文件夹中的DLL的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET控制台应用程序,它引用的DLL。它运行正常,如果DLL是在同一个文件夹中的EXE,但我希望把DLL在不同的文件夹中。我该怎么办呢?

I have a .NET console app that references a DLL. It runs fine if the DLL is in the same folder as the EXE but I would like to put the DLL in a different folder. How can I do that?

推荐答案

如果该DLL是在子文件夹,你可以将此文件夹添加到的AppDomain私人路径

If the dll is in a sub folder you can add this folder to the AppDomain private path.

一个AppDomain的私人bin路径不能一旦AppDomain中已经创建改变(AppDomain.AppendPrivatePath是过时的),如果你不希望创建一个新的AppDomain,您可以修改的probing元素在App.config。

The private bin path of an AppDomain cannot be changed once the AppDomain has been created (AppDomain.AppendPrivatePath is obsolete), if you don't want to create a new AppDomain, you can modify the probing element in the App.config.

如果这不是在子文件夹中,事情变得更加复杂,你可以加载程序集使用完整的路径,但如果它引用其他集,CLR将不能够解决的依赖关系。

If it's not in a sub folder, things get more complicated, you can load the assembly using its full path, but if it references other assembly, the CLR won't be able to resolve the dependencies.

如果你想解决的依赖关系,你可以添加一个处理程序<一href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx">AppDomain.AssemblyResolve并获取所需的装配在特定的文件夹中。

If you want to resolve dependencies, you can add an handler to AppDomain.AssemblyResolve and fetch the needed assembly in your specific folder.

另一种可能性是将这个dll(和依赖性)在GAC中。

Another possibility is to place this dll (and dependencies) in the GAC.

这篇关于加载来自不同文件夹中的DLL的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆