visual-studio 项目参考与 DLL 参考 - 哪个更好?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3047733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Project reference vs. DLL Reference - Which is better?
提问by Zann Anderson
I know there are other questions regarding this subject, and I've looked at this question, but I'd like to see a little bit more discussion and information on both sides of this - is it a better practice to add a project to a solution and reference the project, or to add a reference to the .dll?
我知道关于这个主题还有其他问题,我已经看过这个问题,但我希望看到更多关于这方面的讨论和信息 - 将项目添加到一个更好的做法是解决方案并引用项目,还是添加对.dll 的引用?
采纳答案by Hans Passant
It's not much of a choice. If you have a solution with both projects then use a project reference. If your solution doesn't have the project then you haveto use an assembly reference.
这不是一个选择。如果您有两个项目的解决方案,请使用项目参考。如果您的解决方案没有项目,那么您必须使用程序集引用。
So the real question should probably be: do I create a solution with both projects? Yes, as long as the project is still in the debug stage and liable to require bug fixes.
所以真正的问题应该是:我应该为两个项目创建一个解决方案吗?是的,只要项目仍处于调试阶段并且可能需要修复错误。
回答by ChrisF
If you only have the dll then you're stuck with a dll reference (obviously).
如果您只有 dll,那么您就会遇到 dll 引用(显然)。
If you have the source then it's usually better to use a project reference. There might be cases where you have a utility library that's never going to change, but if there's the slightest chance of you needing a bug fix then having a project reference is going to make debugging a lot easier.
如果您有源代码,那么通常最好使用项目参考。在某些情况下,您可能拥有一个永远不会更改的实用程序库,但是如果您需要修复错误的可能性很小,那么拥有项目参考将使调试变得更加容易。
回答by Franz
Summary - Project Reference by Project vs by DLL
摘要 - 按项目与按 DLL 的项目参考
Reference by project
按项目参考
- code is visible
- finds all references e.g. on a class (because code is visible)
- better for testing (over all)
- better for code redesign (impact)
- 代码可见
- 查找所有引用,例如在一个类上(因为代码是可见的)
- 更适合测试(总体而言)
- 更适合代码重新设计(影响)
Reference by DLL
DLL 引用
- code is hidden
- separation between e.g. framework and project (for deliver of framework)
- quicker compilation (because DLL is already compiled)
- 代码被隐藏
- 例如框架和项目之间的分离(用于框架的交付)
- 更快的编译(因为 DLL 已经编译)
回答by Taylor Leese
Well, project references are helpful when you are building and testing in both debug and release mode. If you directly add a DLL then you are locked into whatever that particular DLL was built as. The project reference allows this to be a build time decision.
好吧,当您在调试和发布模式下构建和测试时,项目引用很有帮助。如果您直接添加一个 DLL,那么您将被锁定在该特定 DLL 的构建方式中。项目参考允许这是一个构建时间决定。
回答by Pradish
Relative to your project architecture, you should always stick to projects within your problem domain. You should be using the GAC, if that is applicable to your environment.
相对于您的项目架构,您应该始终坚持问题域内的项目。如果 GAC 适用于您的环境,您应该使用 GAC。

