.net 项目参考 DLL 版本地狱
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2357476/
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 References DLL version hell
提问by Mr Shoubs
We're having problems getting visual studio to pick up the latest version of a DLL from one of our projects.
我们在让 Visual Studio 从我们的一个项目中获取最新版本的 DLL 时遇到问题。
We have multiple class library projects (e.g. BusinessLogic, ReportData) and a number of web services, each has a reference to a Connectivity DLL we've written (this ref to the connectivity DLL is the problem).
我们有多个类库项目(例如 BusinessLogic、ReportData)和许多 Web 服务,每个服务都有一个对我们编写的连接 DLL 的引用(这个对连接 DLL 的引用是问题所在)。
We always point references to the DLL in the bin/debug folder, (which is where we always build to for any given project) and all custom DLL references have CopyLocal = True and SpecificVersion = False
我们总是指向 bin/debug 文件夹中的 DLL 的引用(这是我们总是为任何给定项目构建的位置)并且所有自定义 DLL 引用都具有 CopyLocal = True 和 SpecificVersion = False
ReportData has a reference to business logic (which also has a reference to connectivity - I don't see why this should cause a problem, but thought it is worth mentioning)
ReportData 引用了业务逻辑(其中也引用了连接性 - 我不明白为什么这会导致问题,但认为值得一提)
The weird thing is, when you click "Add Reference" and browse to Connectivity/bin/debug - you hover the mouse over the DLL file, the correct (latest) version is shown (version and file version are always incremented together), but when you click ok, a previous version number is pulled though. Even when I look in the current projects debug folder (where copy local would put the DLL after compiling) that shows the latest version number. - NO WHERE does can I find the previous version of the DLL outside of visual studio, but in that project references it has the old version - even though the path is correct.
奇怪的是,当您单击“添加引用”并浏览到 Connectivity/bin/debug 时 - 将鼠标悬停在 DLL 文件上,会显示正确的(最新)版本(版本和文件版本总是一起递增),但是当您单击确定时,虽然会拉出以前的版本号。即使我查看显示最新版本号的当前项目调试文件夹(复制本地将在编译后放置 DLL)。- 我无法在 Visual Studio 之外找到以前版本的 DLL,但在该项目引用中,它具有旧版本 - 即使路径是正确的。
I'm at a loss as to where it might be getting the old versions from. Or even why it wants that one.
我不知道从哪里获得旧版本。或者甚至为什么它想要那个。
This is possibly the most frustraighting problem I have ever come across.
这可能是我遇到过的最令人沮丧的问题。
Does anyone know how to ensure the latest version is pulled through (preferably automatically or on compile).
有谁知道如何确保最新版本通过(最好是自动或在编译时)。
EDIT:
编辑:
Although not exactly the scenario I'm dealing with I was reading thisarticle and somewhere it mentions about CLR ignoring revision numbers. Understandable (even though this hasn't been a problem before - we're on revision 39), so I thought I would update the build number, still didn't work. In a vain attempt I though I would update the minor version number and see if that made any difference.
虽然不完全是我正在处理的场景,但我正在阅读这篇文章,并且在某处提到了 CLR 忽略修订号。可以理解(即使这之前不是问题 - 我们在修订版 39),所以我想我会更新内部版本号,但仍然没有用。尽管我会更新次要版本号,看看这是否有什么不同,但徒劳无功。
I'm not saying this is the answer as I have to check quite a few things first, but on the face of it, this seems to have solved my problem...
我不是说这是答案,因为我必须先检查很多事情,但从表面上看,这似乎解决了我的问题......
Further edit: In other class libraries this seems to have solved the problem, however in a test windows application it still pulls a previous version through :(
进一步编辑:在其他类库中,这似乎已经解决了问题,但是在测试 Windows 应用程序中,它仍然通过 :(
If I increment the minor version number again, the same problem come back and I am left with the wrong version being pulled though.
如果我再次增加次要版本号,同样的问题又会出现,但我会留下错误的版本。
Further Edit - I created an entirly new project, added a reference and still had the exact same problem. This suggests the problem is restriced to the project I am referencing. Wish I knew why!
进一步编辑 - 我创建了一个全新的项目,添加了一个参考,但仍然有完全相同的问题。这表明问题仅限于我引用的项目。希望我知道为什么!
Anyone had this problem before and know how to get around it?
任何人以前都遇到过这个问题并且知道如何解决它?
HELP!
帮助!
采纳答案by Mr Shoubs
To overcome this, I removed EVERY reference, then added them all back in again. I don't know why this is the solution.
为了克服这个问题,我删除了每个引用,然后重新添加它们。我不知道为什么这是解决方案。
It is possible that in one project a DLL was incorrect, and it is this incorrect DLL that was pulled through by visual studio and used.
有可能在一个项目中,一个 DLL 不正确,而 Visual Studio 提取并使用的正是这个不正确的 DLL。
Edit: Other times this error has occurred is due to a DDL (A) being referenced in the current project also being referenced by another DLL (B). Not rebuilding this other DLL (B) seems to prevent VS from referencing the correct version of DLL (A) in the current project and thus it brings through an older version of DLL (A).
编辑:其他时候发生此错误是由于当前项目中引用的 DDL (A) 也被另一个 DLL (B) 引用。不重建其他 DLL (B) 似乎会阻止 VS 在当前项目中引用正确版本的 DLL (A),因此它会引入旧版本的 DLL (A)。
回答by Darin Dimitrov
To avoid the dll hellI would recommend you to create a libfolder inside your project and put all shared assemblies in this folder. Next you Add References only from this folder. This way your project is self contained and you know exactly where it is picking the references from. If you want to update some assembly with a newer version you copy it to the libfolder and rebuild your project.
为了避免dll 地狱,我建议您lib在项目中创建一个文件夹并将所有共享程序集放在此文件夹中。接下来,仅从该文件夹添加引用。通过这种方式,您的项目是自包含的,并且您确切地知道它从哪里选择引用。如果要使用较新版本更新某些程序集,请将其复制到lib文件夹并重建项目。
Also make sure you don't the referenced assemblies into the GAC as they might be picked up first.
还要确保不要将引用的程序集放入 GAC,因为它们可能会首先被提取。
回答by sankar
There are few options that you can try.
您可以尝试的选项很少。
- Compile the project and see in output window to verify the assembly path where it is referred from exactly.
- Delete Obj folder before you recompile it.
- Close and reopen the Visual Studio since VS has some weird behavior to keep the cache to hold Dll references.
- If you still see the problem, use this tool to check the reference assembly where it comes from really. Process Explorer.
- 编译项目并在输出窗口中查看以验证其确切引用的程序集路径。
- 在重新编译之前删除 Obj 文件夹。
- 关闭并重新打开 Visual Studio,因为 VS 有一些奇怪的行为来保持缓存以保存 Dll 引用。
- 如果您仍然看到问题,请使用此工具检查参考程序集的真实来源。进程浏览器。
回答by Captain Kenpachi
We (and, as the only .NET developer on our team, by that I mean I) had the exact same problem. I traced it down to a referenced dll, which in turn AGAIN references the dll suffering from versionitis. It seems that because I wasn't updating all the references which in turnreference the dll, it was replaced by an older version at some point during the build process.
我们(并且,作为我们团队中唯一的 .NET 开发人员,我的意思是我)遇到了完全相同的问题。我将其追溯到一个引用的 dll,而后者又引用了患有版本炎的 dll。看来,因为我没有更新其所有引用又将基准的DLL,它在某一点在构建过程中替换旧版本。
One of the symptoms I experienced was that when I am in the code editor, the new class I added to the referenced project would be coloured appropriately, but when I hit Build, it changes back to black and I get a message saying the class does not exist (along with a very sarcastic "Ar you missing an assembly reference?"). This led me to believe that the problem has to happen during the Build phase.
我遇到的一个症状是,当我在代码编辑器中时,我添加到引用项目的新类会被适当地着色,但是当我点击 Build 时,它又变回黑色,并且我收到一条消息说该类没有不存在(以及非常讽刺的“您是否缺少程序集参考?”)。这让我相信问题必须在构建阶段发生。
I would therefore suggest building any and every other project that points to this DLL and re-add their references too.
因此,我建议构建指向此 DLL 的任何其他项目,并重新添加它们的引用。
回答by Rowland Shaw
Have you tried adding the reference as a Project Reference? i.e. Add Reference... -> Projects tab -> Select your project
您是否尝试将参考添加为项目参考?即添加引用... -> 项目选项卡 -> 选择您的项目
回答by smirkingman
Enable FusionLog and after the DLL fails to load, open the file with the DLL's name in the folder C:\FusionLog\Default\devenv.exe. This will show the path from where the DLL was really loaded.
启用 FusionLog,在 DLL 加载失败后,打开文件夹 C:\FusionLog\Default\devenv.exe 中具有 DLL 名称的文件。这将显示 DLL 真正加载的路径。
In my case, an old version had mysteriously appeared in
就我而言,旧版本神秘地出现在
C:\Program Files\Microsoft Visual Studio 10\Common7\IDE !
C:\Program Files\Microsoft Visual Studio 10\Common7\IDE !
To stop this ever happening again, I added a security rule "Deny Write" to Everyone on Common7\IDE.
为了阻止这种情况再次发生,我在 Common7\IDE 上为每个人添加了一条安全规则“拒绝写入”。
回答by Mario Levesque
I had a problem similar to what is described here except that my solution to the problem had to do with how I was compiling the code. There is a difference between build, clean and Rebuild. In my case, I was just using a Build between my changes and the dll from the dependent solution were not being carried over with all the changes to the other solution where the reference was set. I solved it by using Rebuild which cleans, compiles and links all source files regardless of whether they changed or not. Then the dll from the the first solution was updated and copied over automatically to the 2nd solution where the reference was set and the problem was solved. Cheers, I hope this helps.
我遇到了一个类似于这里描述的问题,只是我对问题的解决方案与我编译代码的方式有关。构建、清理和重建之间存在差异。就我而言,我只是在我的更改和依赖解决方案中的 dll 之间使用了 Build 并没有将所有更改转移到设置了引用的其他解决方案中。我通过使用 Rebuild 解决了这个问题,它会清理、编译和链接所有源文件,无论它们是否更改。然后第一个解决方案中的 dll 被更新并自动复制到第二个解决方案,在那里设置了引用并解决了问题。干杯,我希望这会有所帮助。
回答by Toke Breer-Mortensen
Similar symptoms - problem was in "Referene paths" in Project Properties, Reference.
类似的症状 - 问题出在项目属性、参考中的“参考路径”中。
Full descrtiption and solution here: Referenced assemblies automatically replaced by visual studiovisual-studio/22810867#22810867
此处的完整说明和解决方案: 引用的程序集自动替换为 Visual Studiovisual-studio/22810867#22810867
回答by Ranjan Shrestha
Check Out this things:
看看这些东西:
- if problematic dll were referenced by both host web application and its referenced one. e.g. say, your web application uses abc.dll (problematic) and 1 other dll xyz.dll(i.e. class project which also reference abc.dll).
- 如果有问题的 dll 被主机 Web 应用程序及其引用的应用程序引用。例如,您的 Web 应用程序使用 abc.dll(有问题)和 1 个其他 dll xyz.dll(即也引用 abc.dll 的类项目)。
In this case, suppose, you've updated abc.dll from version 1 to version 2 and re-referenced in your web application. but during building process, the version 2 of abc.dll will change back to version 1, because, xyz.dll uses version 1 and web application overwrite abc.dll version 2 back to abc.dll version 1 during auto update on xyz.dll.
在这种情况下,假设您已将 abc.dll 从版本 1 更新到版本 2 并在您的 Web 应用程序中重新引用。但是在构建过程中,abc.dll 的版本 2 将变回版本 1,因为 xyz.dll 使用版本 1 并且 Web 应用程序在 xyz.dll 的自动更新期间将 abc.dll 版本 2 覆盖回 abc.dll 版本 1 .
Solution: place updated version of abc.dll version 2 in class project bin of xyz.dll , too
解决方案:将更新版本的 abc.dll 版本 2 也放在 xyz.dll 的类项目 bin 中
Hope, above details will help, good luck
希望以上细节会有所帮助,祝你好运
回答by David Tjandra
One possible reason is the Reference PATHs. If there's any reference to the old dll folder, VS will use it as the main reference, even though you added the new dll reference.
一种可能的原因是参考路径。如果有任何对旧 dll 文件夹的引用,VS 将使用它作为主要引用,即使您添加了新的 dll 引用。

