引用不在根目录中的第三方装配体 [英] Referencing a 3rd party assembly which is not located in the root location

查看:88
本文介绍了引用不在根目录中的第三方装配体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio 2010 C#项目,该项目创建一个.exe,并且该项目正在使用某些第三方类库。
我的项目位于:/ MyFramWork / tests / test1
第三方库位于:/ MyFrameWork / bin / utils /



I通过使用参考->添加参考->浏览将参考添加到库中。我可以看到在项目文件中一切都很好:

.... \bin\utils\log4net.dll
False



我想引用第三方库,而不使用复制本地选项。但是,如果我不使用该选项,则找不到该库,并且出现异常。



我的问题是:有没有办法指定第三方库应该在.... binbinutils中找到。似乎当.exe生成时,.csproj中的信息会丢失。

解决方案

默认情况下,.NET应用看起来



您有三个选择:


$,因为它们的依赖关系仅在两个位置:EXE目录和GAC(全局程序集缓存)。 b $ b

  • 您可以确保将依赖项复制到与EXE相同的目录中(这是复制本地所做的)。在大多数情况下,这是最好的选择,这就是为什么当您引用尚未在GAC中的程序集时将其作为默认值的原因。

  • 您可以使用 gacutil 。如果您的依存关系不会改变,将在每台开发机器上位于不同的位置(即,相对路径无法正常工作),并且您想从许多不同的地方使用它,那么这可能是一个不错的选择项目。但是,如果依存度仍在积极发展中并且经常变化,这将是一个巨大的痛苦。您还需要确保将DLL放入应用程序部署到的每台计算机上的GAC中。

  • 您可以自定义依赖项加载行为,使其在其他地方显示,正如汉斯在评论中指出的那样。



通常,您只需要使用本地复制即可;


这是非常明智的默认设置。您应该有一个令人信服的理由要做任何不同的事情。


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/

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: ....\bin\utils\log4net.dll False

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.

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

解决方案

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

You have three choices:

  • You can make sure the dependency gets copied into the same directory as your EXE (this is what Copy Local does). This is the best choice most of the time, which is why it's the default when you reference an assembly that's not already in the GAC.
  • You can install your dependency into the GAC using gacutil. This might be a good choice if your dependency isn't going to change, is going to be in a different location on every development machine (i.e. if relative paths won't work well), and if you want to use it from many different projects. But it's a major pain if the dependency is still under active development and changing frequently. You'll also need to make sure to put the DLL into the GAC on every computer you deploy your app to.
  • You can customize the dependency-loading behavior so it looks in other places, as Hans noted in his comment. This is an advanced option and comes with a whole new set of headaches.

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

这篇关于引用不在根目录中的第三方装配体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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