对常见dll的绝对引用 [英] Absolute reference to common dll's

查看:64
本文介绍了对常见dll的绝对引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#程序集vs2005中添加对dll库的引用.问题是,我不想将其复制到可执行文件的文件夹中(我知道,复制本地-> false),并且我希望它位于特定的文件夹中.

示例:在项目myProgram(-> myProgram.exe,例如位于"c:\ SomePrograms \ myProgram \"-或其他位置)中,我想添加对库"CommonUtils.dll"的引用",它始终位于"c:\ ourCommonLibs \"中,我想在那里访问它(没有本地副本,没有动态链接,也没有相对路径,谢谢).

Hi, I want to add a reference to a dll library in a c# assembly, vs2005. The problem is, I don''t want it to copy to the folder of the executable (Copy Local -> false, I know) and I want it to be in a specific folder.

Example: In project myProgram (-> myProgram.exe, located for example at "c:\SomePrograms\myProgram\" - or anywhere else) I want to add a reference to library "CommonUtils.dll" that is ALWAYS located in "c:\ourCommonLibs\", and I want to access it right there (no local copy and no dynamic linking and no relative path, thank you).

Is there a way to do that?

推荐答案

为dll提供一个强名称并将其安装在GAC(全局程序集缓存)中.需要相对路径.
Give dll a strong name and install it in GAC(Global Assembly Cache)... This would fix the location and no relative path needed.


我认为,如果将dll放在同一文件夹中,它将按原样运行.否则,应用程序会将相关的dll复制到其自己的文件夹中.

我认为最好的解决方法是不要完全引用dll.而是使用System.Reflection从另一个动态加载dll.这将使您可以使用相对地址来引用dll.

使用

Assembly.Load

阅读此内容:
http://support.microsoft.com/kb/837908 [
I think if you place the dlls in the same folder it will work as it is. Otherwise application copies the related dlls to its own folder.

I think the best workaround is not to reference the dll altogether. Rather use System.Reflection to load the dll dynamically from the other one. This will let you use Relative address for referencing the dll.

Use

Assembly.Load

Read this :
http://support.microsoft.com/kb/837908[^]


首先,不要假定必须有C: \在计算机上驱动器.使公共dll路径"可配置.
接下来,通过反射(myAssembly = System.Reflection.Assembly.LoadFrom(path))加载dll,然后实例化所需的类(myAssembly.CreateInstance(...)).您可能需要加载引用的程序集(AssemblyName[] referenced = myAssembly.GetReferencedAssemblies()).
First of all, do not assume that there must be a C:\ drive on the computer. Make your "common dlls path" configurable.
Next, load the dlls via reflection (myAssembly = System.Reflection.Assembly.LoadFrom(path)), then instantiate the required classes (myAssembly.CreateInstance(...)). You may need to load referenced assemblies (AssemblyName[] referenced = myAssembly.GetReferencedAssemblies()).


这篇关于对常见dll的绝对引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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