为什么我的 .NET 类库中的所有引用都带有黄色感叹号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3669769/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 14:43:23  来源:igfitidea点击:

Why would all of my references have yellow exclamation points on them in my .NET class library?

.netvisual-studio-2008reference

提问by Luc

I've been developing a class library for quite sometime and all of the sudden, sometime last week, I opened my project and all of my references have yellow exclamation points on them now (System.dll, System.Drawing.dll, etc..). I've tried removing the references and re-adding them to fix any broken reference paths, but they continue to show yellow exclamation points on them.

我一直在开发一个类库很长一段时间,突然之间,上周的某个时候,我打开了我的项目,现在我的所有引用都带有黄色感叹号(System.dll、System.Drawing.dll 等)。 .) 我尝试删除引用并重新添加它们以修复任何损坏的引用路径,但它们继续显示黄色感叹号。

Nothing had changed since the last time I'd opened the project. The only thing that was different from the last time I'd opened the project was that this time I opened it from directly inside of .NET from another project. For example, I was working on a .NET 3.5 web project, then clicked File -> Open Recent Files -> My Other Solution. This closed my current current 3.5 web solution and opened the 2.0 class library solution and the problem appeared for the first time. I'm not sure how (or why) this would cause a problem, but I'm leaning toward the fact that Visual Studio got confused or something and now my assemblies are all invalid on this 2.0 class library project. (?)

自从我上次打开该项目以来,没有任何变化。与上次打开项目时唯一不同的是,这次我直接从另一个项目的 .NET 内部打开了它。例如,我正在处理一个 .NET 3.5 Web 项目,然后单击文件 -> 打开最近的文件 -> 我的其他解决方案。这关闭了我当前当前的3.5 web解决方案,打开了2.0类库解决方案,问题第一次出现。我不确定这会如何(或为什么)导致问题,但我倾向于 Visual Studio 感到困惑或其他原因,现在我的程序集在这个 2.0 类库项目中全部无效。(?)

What would cause this to happen and how can I fix it? I've looked around the web, but I only see that people have suggested to remove the references and re-add them; which I've done, to no avail.

什么会导致这种情况发生,我该如何解决?我环顾了整个网络,但我只看到人们建议删除引用并重新添加它们;我已经做了,无济于事。

I'm considering starting a new project and copying over all of my source files one by one, but would really like to avoid all this if possible.

我正在考虑开始一个新项目并一个一个地复制我的所有源文件,但如果可能的话,我真的很想避免这一切。

Thanks in advance!

提前致谢!

采纳答案by code4life

Using the Solution Explorer, right mouse click and select Unload Project and then select Edit (name of your csproj file) to be able to edit the .csproj file directly in VS.

使用解决方案资源管理器,右键单击并选择卸载项目,然后选择编辑(您的 csproj 文件的名称),以便能够直接在 VS 中编辑 .csproj 文件。

Under one of the <ItemGroup>nodes you will find subnodes tagged Reference. Ensure that the HintPathnode value points to a valid path. Also double check the nodes SpecificVersionand Privatefor valid values.

在其中一个<ItemGroup>节点下,您会找到标记为 的子节点Reference。确保HintPath节点值指向有效路径。还要仔细检查节点SpecificVersionPrivate有效值。

Hopefully evaluating these values will help you resolve your problem.

希望评估这些值将帮助您解决您的问题。

回答by Phill

Just to add to this. I recently had an issue where I was adding references that had the TargetFramework set to .NET 4.0 to a Visual Studio 2008 project. All you get is a yellow exclamation mark and explanation.

只是为了补充这一点。我最近遇到了一个问题,我将 TargetFramework 设置为 .NET 4.0 的引用添加到 Visual Studio 2008 项目。你得到的只是一个黄色的感叹号和解释。

Once I realised I picked the wrong release binaries it seemed obvious!

一旦我意识到我选择了错误的发布二进制文件,这似乎很明显!

回答by lankitha

Check weather the project .NET framework is equal or greater than reference .Net framework

检查天气项目 .NET 框架等于或大于参考 .Net 框架

回答by Reza Bayat

my problem was difference in target .NET framework versions set on the projects. the first was set to .NET 4.0 and the second was .NET 4.5 changing it solved my problem

我的问题是在项目上设置的目标 .NET 框架版本不同。第一个设置为 .NET 4.0,第二个是 .NET 4.5 改变它解决了我的问题

回答by JamesCM

I got the same issue with a project opened in Visual Studio 2015 recently.

我最近在 Visual Studio 2015 中打开的一个项目遇到了同样的问题。

The error came out when I've relocated a few times the physical location of the solutions default package repositories and deliberately changed the value of the repositoryPath in the NuGet.Config

当我重新定位解决方案默认包存储库的物理位置几次并故意更改 NuGet.Config 中的 repositoryPath 的值时出现错误

In my case, I needed to remove an element whose path pointed to by the condition attribute is invalid that is inside the Target section of the csproj file.

就我而言,我需要删除 csproj 文件的 Target 部分中的条件属性指向的路径无效的元素。

<Error Condition="!Exists('..\..\..\..\..\Packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" 
       Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\Packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />

Also, this error is reproduced when the usual Package folder is removed or relocated elsewhere. One should then update this value along with the ItemGroups.

此外,当通常的 Package 文件夹被删除或重新定位到其他地方时,会重现此错误。然后应该随 ItemGroups 一起更新此值。

回答by pashute

Change the target DotNet framework to be the same between the two projects and all will work fine. (Especially if you "upgrade")

将两个项目之间的目标 DotNet 框架更改为相同,一切都会正常工作。(特别是如果你“升级”)

回答by Kr15

I had the same issue with yellow exclamation marks on a bounch of sourcecode files of a solution which is checked-in/maintained by the TFS. There was no regularity as for which files actually had an yellow exclamation mark and which not. By researching the cause for this problem, i could see that those files with yellow exclamation marks actually where not even retrieved from the TFS down onto my harddisc. I checked the HintPath etc. in .csproj files and everything looked fine there and also no other tip from this thread could help me solving the problem.

我遇到了与 TFS 签入/维护的解决方案的一堆源代码文件上的黄色感叹号相同的问题。至于哪些文件实际上有黄色感叹号,哪些没有,没有规律。通过研究这个问题的原因,我可以看到那些带有黄色感叹号的文件实际上甚至没有从 TFS 检索到我的硬盘上。我检查了 .csproj 文件中的 HintPath 等,那里的一切看起来都很好,并且该线程中的其他提示也无法帮助我解决问题。

WHAT FINALLY HELPED ME was to do the following: In solution explorer right-click onto Project -> Get Specific Version... -> ('Version Type: Latest Version already selected') -> + enable checkbox 'Overwrite all files even if the local version matches the specified version' -> click 'Get' button

最终帮助我的是执行以下操作:在解决方案资源管理器中右键单击项目 -> 获取特定版本... ->(“版本类型:已选择最新版本”)-> + 启用复选框“覆盖所有文件,即使本地版本与指定版本匹配' -> 单击“获取”按钮

After i did that all sourcecode files could be successfully retrieved from the TFS and the yellow exclamation marks disappeared! I hope this helps somebody who is having the same problem!

在我这样做之后,所有的源代码文件都可以成功地从 TFS 中检索出来,黄色的感叹号消失了!我希望这可以帮助遇到同样问题的人!

回答by martinoss

I had the same problem, after copying project-folders from another project as starting point for a new solution.

从另一个项目复制项目文件夹作为新解决方案的起点后,我遇到了同样的问题。

All project referenced that this yellow exclamation mark, even the references to framework assemblies.

所有项目都引用了这个黄色感叹号,甚至是对框架程序集的引用。

What finally helped was to ensure, that the folder ".nuget" (Including Nuget.Config, NuGet.exe, NuGet.targets)was in my solution folder. Then I did "Restore Nuget Packages"in the Context menu of the solution. Now all exclamation marks has gone!

什么终于帮是保证,该文件夹“.nuget”(包括Nuget.Config,NuGet.exe,NuGet.targets)是我的解决方案文件夹中。然后我在解决方案的上下文菜单中做了“恢复 Nuget 包”。现在所有的感叹号都消失了!

回答by SaiyanGirl

In my case it turns out that the dllhad a different version than the nuget package. Even though 1.1.14 was downloaded and the folder was called 1.1.14, upon inspection of the dll properties (under the details tab), I noticed that it was version 1.1.13.

就我而言,事实证明dllnuget 包的版本不同。尽管下载了 1.1.14 且文件夹名为 1.1.14,但在检查 dll 属性(在详细信息选项卡下)时,我注意到它是 1.1.13 版。

Therefore, my csprojhad to reference a 1.1.14 folder, but a 1.1.13 dll. I changed the csprojfile to indicate this.

因此,我csproj必须引用 1.1.14 文件夹,但引用 1.1.13 dll。我更改了csproj文件以表明这一点。

回答by Ajinkya Surve

Problem:This is what happened with me, I was mapping my TFS repository to a folder under C:\Users\myUserNameFolder\ The "myUserNameFolder" has special permissions for the fact that its a System folder, due to which the referenced dlls in the solution were getting the Yellow triangle and whenever I tried to re-reference all the dlls they were still getting the same Yellow triangle mark. Solution:I remapped my TFS repository to a normal folder on C:\ and that did the trick. Hope this helps to someone..

问题:这就是我遇到的情况,我将 TFS 存储库映射到 C:\Users\myUserNameFolder\ 下的文件夹。“myUserNameFolder”具有特殊权限,因为它是一个 System 文件夹,因此引用了 dll解决方案是获得黄色三角形,每当我尝试重新引用所有 dll 时,它们仍然获得相同的黄色三角形标记。 解决方案:我将我的 TFS 存储库重新映射到 C:\ 上的一个普通文件夹,并且成功了。希望这对某人有帮助..

P.S.This happened in VS 2015.

PS这发生在 VS 2015 中。