.net 参考具体版本是对还是错?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1063459/
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
.net reference specificversion true or false?
提问by sptremblay
We are two companies who are working on the same project, in the same application. On a weekly basis we exchange onlyour assemblies (not the code) and reference each other's dll.
我们是在同一个应用程序中从事同一个项目的两家公司。我们每周只交换我们的程序集(而不是代码)并引用彼此的 dll。
What is the best practice regarding the specificversionwhen adding reference to our project.
Specifically, when should we use a specificversionvalue of trueand in what case should we use false.
specificversion添加对我们项目的引用时的最佳实践是什么。具体来说,我们应该在什么时候使用 的specificversion值true以及在什么情况下应该使用false。
回答by Joseph
This answer is going to be based on the assumption that you are versioning your dlls.
这个答案将基于您正在对 dll 进行版本控制的假设。
If you set SpecificVersion to true (which is the default when adding a reference), then the project will reference to that dll with a particular version (say for instance 1.0.0.0). If, at a later time, you're given a new dll (say 1.0.1.0), then you will have to remove the old dll reference and add the new reference. This is because the project is specifically looking for 1.0.0.0 when you have a new version 1.0.1.0.
如果您将 SpecificVersion 设置为 true(这是添加引用时的默认设置),则项目将引用具有特定版本(例如 1.0.0.0)的 dll。如果稍后给您一个新的 dll(比如 1.0.1.0),那么您将不得不删除旧的 dll 引用并添加新的引用。这是因为当您有新版本 1.0.1.0 时,该项目会专门寻找 1.0.0.0。
The alternative to this is to set the SpecificVersion to false, which tells the project to find the latest available dll and use that one. The problem with this is that the project is now required to "hunt" in various places for the dll you've referenced, which can increase your build time. It will do this even though it knows the path of the dll you've referenced. I'm not sure if this is a bug or if this is done by design. It might be checking to see if there are any newer dlls besides the one you've referenced (perhaps in the GAC or elsewhere).
另一种方法是将 SpecificVersion 设置为 false,这会告诉项目找到最新的可用 dll 并使用该 dll。这样做的问题是,项目现在需要在不同位置“寻找”您引用的 dll,这会增加您的构建时间。即使它知道您引用的 dll 的路径,它也会这样做。我不确定这是一个错误还是设计使然。它可能会检查除了您引用的 dll 之外是否还有任何更新的 dll(可能在 GAC 或其他地方)。
Here's an articlethat describes this issue in more detail.
这里有一篇文章更详细地描述了这个问题。

