我有一个问题与Visual Studio的c#解决方案。它会显示完全随机的错误,但项目会构建。现在,我有33个有错误的文件,我可以在所有文件中看到红色的弯曲线。

我尝试清理/重新构建解决方案,关闭Visual Studio,甚至重新启动计算机。我可以修改.cs文件,并看到解决方案中的更改。

有人知道为什么会这样吗?


当前回答

我刚刚遇到这个问题后,恢复了一个git提交,添加文件回到我的项目。

清理和重建项目没有起作用,即使我在每一步之间关闭VS。

最终起作用的方法是将文件重命名为其他文件,然后再将其更改回来。facepalm指:

其他回答

如果你有ReSharper,试着清空ReSharper缓存:

在菜单中,ReSharper > Options > Environment > General > Clear cache

和禁用和重新启用ReSharper:

在菜单中,工具>选项> ReSharper > General > Suspend / Restore

在我的情况下,vs从未在项目属性>引用中保留导入的名称空间

当我试图再次添加/检查它们时,我不能和vs抛出一个错误,当保存项目vs崩溃时。当我重新打开所有标准导入的名称空间(system。数据等)都被再次勾选,然后它就能正确识别一切

在我的例子中,帮助了很多事情:

deleting all old not needed files which were previously excluded from the project closing VS deleting all the bin folder contents deleting .vs folder Clean/Rebuild after that I still had some spurious errors, however the amount was significantly lower (from 200 to around 8) and the errors referred only to a resource dictionary path in Generic.xaml e.g. <ResourceDicitonary Source="example/path/somefile.xaml"> when I played around with the path trying to change it to a wrong one re-building then correcting it and rebuilding again, then this finally cleared all errors. It was specifically WPF project if that's relevant.

我在VS2019中的症状是我会构建一些错误。然后修复错误,构建就可以工作了,如Output窗口所示。但是错误窗口仍然显示旧的错误。我可以运行得很好。关闭VS2019并重新打开解决了这个问题,但只是一段时间。这在版本16.4.3开始发生

这个解决方案似乎对我很有效:

取消勾选工具->选项->项目和解决方案->通用->允许并行项目初始化

我发现这个解决办法埋在这里的评论:https://developercommunity.visualstudio.com/content/problem/483450/vs-2019-intellisense-reports-compile-errors-when-r.html

我遇到过这样的问题,智能感知似乎不能识别一个项目的存在(很多“找不到这种类型”,“这个名称空间不存在”等错误)。

在所有引用项目中删除并重新添加项目引用可以解决问题,但是可以通过编辑问题项目的.proj文件来修复潜在的原因。

在“缺失的”project' .csproj文件的顶部附近有一个元素:

<ProjectGuid>{GUID}</ProjectGuid>

在所有引用项目中。csproj文件都是项目引用:

<ProjectReference Include="..\OffendingProject\OffendingProject.csproj">
  <Project>{ANOTHER-GUID}</Project>
  <Name>Offending Project</Name>
</ProjectReference>

引用的GUID与项目的GUID不匹配。用{ANOTHER-GUID}替换上面的{GUID}解决了这个问题,而不必经过每个引用项目。