引用不在根位置的第 3 方程序集 [英] Referencing a 3rd party assembly which is not located in the root location

查看:10
本文介绍了引用不在根位置的第 3 方程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Visual Studio 2010 C# 项目,它创建了一个 .exe,这个项目使用了一些 3rd 方类库.我的项目位于:/MyFramWork/tests/test13rd 方库位于:/MyFrameWork/bin/utils/

I have a Visual Studio 2010 C# project which creates an .exe and this project is using some 3rd party class library. My project is located in: /MyFramWork/tests/test1 3rd party library is located at: /MyFrameWork/bin/utils/

我通过使用引用->添加引用->浏览来添加对库的引用.我可以看到在项目文件中一切正常:....inutilslog4net.dll错误的

I am adding the reference to the library by using References->Add Reference->Browse. I can see that in the project file all is fine: ....inutilslog4net.dll False

我想在不使用复制本地"选项的情况下引用第 3 方库.但是,如果我不使用该选项,则找不到该库,并且会出现异常.

I would like to reference the 3rd party library without using the option "Copy Local". However if I don't use the option, the library is not found and I get an exception.

我的问题是:有没有办法指定应该在 ....inutils 中找到第 3 方库.似乎当 .exe 获得构建时,来自 .csproj 的信息丢失了.

My question is: Is there a way to specify that the 3rd party library should be found at ....inutils. It seems that when the .exe gets build the information from the .csproj gets lost.

推荐答案

默认情况下,.NET 应用程序仅在两个位置查找其依赖项:EXE 目录和 GAC(全局程序集缓存).

By default, .NET apps look for their dependencies in only two places: the EXE directory, and the GAC (Global Assembly Cache).

您有三个选择:

  • 您可以确保将依赖项复制到与您的 EXE 相同的目录中(这就是 Copy Local 所做的).大多数情况下,这是最佳选择,这就是为什么当您引用 GAC 中尚未包含的程序集时,它是默认设置.
  • 您可以使用 gacutil.如果您的依赖项不会改变,将在每台开发机器上的不同位置(即,如果相对路径不能正常工作),并且如果您想从许多不同的地方使用它,这可能是一个不错的选择项目.但是,如果依赖项仍在积极发展并经常变化,那将是一个很大的痛苦.您还需要确保将 DLL 放入您部署应用的每台计算机上的 GAC 中.
  • 正如 Hans 在评论中指出的那样,您可以自定义依赖项加载行为,使其在其他地方看起来.这是一个高级选项,但带来了一系列全新的问题.

通常,您只需使用 Copy Local;这是一个非常明智的默认设置.你应该需要一个相当令人信服的理由来做任何不同的事情.

Normally, you would just use Copy Local; it's a very sensible default. You should need a fairly compelling reason to do anything different.

这篇关于引用不在根位置的第 3 方程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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