C# 即使项目生成,Visual Studio 也会显示错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17703004/
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
Visual Studio displaying errors even if projects build
提问by GammaOmega
I have a problem with Visual Studio on a C# solution. It displays totally random errors, but the projects build. Right now, I have 33 files with errors, and I can see red squiggly lines in all of them.
我在 C# 解决方案上遇到 Visual Studio 问题。它显示完全随机的错误,但项目构建。现在,我有 33 个文件有错误,我可以在所有文件中看到红色波浪线。
I tried cleaning / rebuilding the solution, closing Visual Studio and even restarting my computer. I also made sure to do the steps described in Debugging runs even with compiler's errors in Visual Studio. I can modify .cs files and I see the changes in the solution.
我尝试清理/重建解决方案,关闭 Visual Studio 甚至重新启动我的计算机。我还确保执行调试运行中描述的步骤,即使在 Visual Studio 中出现编译器错误。我可以修改 .cs 文件并看到解决方案中的更改。
Does anyone have an idea about why it does that?
有没有人知道为什么这样做?
采纳答案by GammaOmega
If you have ReSharper, try emptying the ReSharper cache:
如果您有 ReSharper,请尝试清空 ReSharper 缓存:
In menu, ReSharper > Options > Environment > General > Clear Caches
在菜单中,ReSharper > 选项 > 环境 > 常规 > 清除缓存
and disabling and re-enabling ReSharper:
并禁用和重新启用 ReSharper:
In menu, Tools > Options > ReSharper > General > Suspend / Restore
在菜单中,工具 > 选项 > ReSharper > 常规 > 暂停/恢复
回答by Daniel Nachtrub
Perhaps you try to reset your intellisense cache. I've had a similar issue in visual studio 2012 when working in a large project with many partial class definitions. Reducing the partials solved the problem partially, clearing the intellisense cache also - for a while.
也许您尝试重置智能感知缓存。我在 Visual Studio 2012 中遇到了类似的问题,当时我在一个包含许多部分类定义的大型项目中工作。减少部分解决了部分问题,也清除了智能感知缓存 - 一段时间。
回答by ionutioio
Try hovering with the mouse over the underlined elements. It should normally tell you what the problem. To see a list of all the errors/warnings, go to View => Error List. A table should open on the bottom of the IDE with all the errors/warnings listed.
尝试将鼠标悬停在带下划线的元素上。它通常应该告诉你什么问题。要查看所有错误/警告的列表,请转到查看 => 错误列表。IDE 底部应打开一个表格,其中列出了所有错误/警告。
回答by Neolisk
Clearing Resharper's cachedid not help in my case, tried suspend/restore, and also Repair Resharper, using latest download off JetBrains' website - neither of these helped. This is after I tried close/reopen VS, restart my machine, repeat, Build/Rebuild and combination thereof.
清除 Resharper 的缓存在我的情况下没有帮助,尝试suspend/restore,并使用 JetBrains 网站上的最新下载修复 Resharper - 这些都没有帮助。这是在我尝试关闭/重新打开 VS、重新启动我的机器、重复、构建/重建及其组合之后。
It's interesting that suspending Resharper seemed to solve the problem after the 2ndrestart of VS, but it was back after I enabled Resharper <-- I tried to do this sequence 2-3 times to ensure the pattern.
有趣的是,暂停 Resharper 似乎在VS的第二次重启后解决了问题,但在我启用 Resharper 后又回来了<--我尝试执行此序列 2-3 次以确保模式。
Anyway, I was still having issues when I found this article:
无论如何,当我找到这篇文章时,我仍然遇到了问题:
So I deleted the hidden .SUO fileon the same folder level with solution, and it magically solved all reds.
所以我用解决方案删除了同一文件夹级别的隐藏.SUO文件,它神奇地解决了所有红色问题。
Note - for Visual Studio 2015, the .SUOfile is in .vs/[solution_name]/v14hidden folder.
注意 - 对于 Visual Studio 2015,.SUO文件位于.vs/[solution_name]/v14隐藏文件夹中。
回答by Philip C
I had a problem like this where Intellisense didn't seem to recognise the existence of one project (lots of "can't find this type", "this namespace doesn't exist", etc. errors).
我遇到了这样的问题,Intellisense 似乎没有识别出一个项目的存在(很多“找不到这种类型”、“这个命名空间不存在”等错误)。
Removing and re-adding the project reference in all the referencing projects would fix the issue, but the underlying cause could be fixed by editing the .proj file of the problem project.
在所有引用项目中删除并重新添加项目引用将解决该问题,但可以通过编辑问题项目的 .proj 文件来修复根本原因。
Near the top of the "missing" project' .csproj file is an element:
在“失踪”项目的 .csproj 文件顶部附近是一个元素:
<ProjectGuid>{GUID}</ProjectGuid>
and in all of the referencing projects .csproj files were project references:
并且在所有引用项目中,.csproj 文件都是项目引用:
<ProjectReference Include="..\OffendingProject\OffendingProject.csproj">
<Project>{ANOTHER-GUID}</Project>
<Name>Offending Project</Name>
</ProjectReference>
The referencing GUID didn't match the project's GUID. Replacing {GUID}
above with {ANOTHER-GUID}
fixed the problem without having to go through every referencing project.
引用 GUID 与项目的 GUID 不匹配。将{GUID}
上述替换为{ANOTHER-GUID}
修复了问题,而无需通过每个引用项目。
回答by pixel
I cleaned solution, closed VS, reopened it, build solution, and red unresolved lines were cleaned and build succeeded.
我清理了解决方案,关闭了VS,重新打开了它,构建了解决方案,并清除了红色未解析的行并成功构建。
回答by Technobabble
Occasionally I have to do a custom clean by going through all of the projects and manually deleting the "bin" and "obj" folders. To see them in Visual Studio, you'll have to enable hidden files and folders for each project. After this is done, rebuild the solution.
有时,我必须通过浏览所有项目并手动删除“bin”和“obj”文件夹来进行自定义清理。要在 Visual Studio 中查看它们,您必须为每个项目启用隐藏文件和文件夹。完成后,重建解决方案。
回答by meJustAndrew
Sometimes if you just clean solution the errors are disappearing, but they may eventualy come back afer a while or at the next build.
有时,如果您只是清理解决方案,错误就会消失,但它们最终可能会在一段时间后或在下一次构建时再次出现。
回答by TTT
tldr;Unload and reload the problem project.
tldr; 卸载并重新加载有问题的项目。
When this happens to me I (used to) try closing VS and reopen it. That probably worked about half of the time. When it didn't work I would close the solution, delete the .suo file (or the entire .vs folder) and re-open the solution. So far this has always worked for me (more than 10 times in the last 6 months), but it is slightly tedious because some things get reset such as your build mode, startup project, etc.
当这发生在我身上时,我(曾经)尝试关闭 VS 并重新打开它。这可能有一半的时间。当它不起作用时,我会关闭解决方案,删除 .suo 文件(或整个 .vs 文件夹)并重新打开解决方案。到目前为止,这对我来说一直有效(在过去 6 个月中超过 10 次),但它有点乏味,因为有些东西会被重置,比如你的构建模式、启动项目等。
Since it's usually just one project that's having the problem, I just tried unloading that project and reloading it, and this worked. My sample size is only 1 but it's much faster than the other two options so perhaps worth the attempt. I suspect this works because it writes to the .suo file, and perhaps fixes the corrupted part of it that was causing the issue to begin with.
由于通常只有一个项目出现问题,我只是尝试卸载该项目并重新加载它,这奏效了。我的样本大小只有 1,但它比其他两个选项快得多,所以也许值得一试。我怀疑这是有效的,因为它写入 .suo 文件,并且可能修复了导致问题开始的损坏部分。
Note: this appears to work for VS 2019, 2017, and 2015.
注意:这似乎适用于 VS 2019、2017 和 2015。
回答by Manojkumar Sachdev
I solved this problem by deleting the temporary files of Microsoft .NET framework. Location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files and C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
我通过删除 Microsoft .NET 框架的临时文件解决了这个问题。位置:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files 和 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files