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

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

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


当前回答

REM DELETE ALL VS HIDDEN SOLUTION OPTION FILES
DEL /A:H /S *.SUO

其他回答

在尝试了所有列出的选项后,我发现了另一个原因,为什么会发生这种情况。如果有人以zip文件的形式向你发送源代码,或者你下载了zip文件,Windows可能已经阻止了所有文件。2种解决方法:

方法1:

右键单击原始Zip文件->选中“解除封锁”->单击应用

方法2:

如果这不是一个选项,而不是打开解决方案文件夹中的每个文件的属性,只需打开power shell并使用以下方法递归地解除阻塞:

Get-ChildItem -Path 'C:\<ROOT FOLDER OF SOLUTION>\' -Recurse | Unblock-File

我体验过智能感知显示不存在的分散注意力的错误,但仍然能够在Visual Studio 2019中构建和调试项目。此问题在Visual Studio 2017中没有出现。在这个问题上,我们无法导航到Visual Studio中的各种参考。

在尝试了所有发布的选项并找到这篇关于导航符号的文章后:https://stackoverflow.com/a/49100341/999011

我们这种情况的解决方案与Microsoft.Net.Compilers & 项目文件中的Microsoft.CodeDom.Providers.DotNetCompilerPlatform引用,在上面的帖子中提到过。

然而,我从来没有更新过它们,我只是发现在项目文件中有多个对不同版本的引用。在清理完这些文件后,每个包只有一个引用 Microsoft.CodeDom.Providers。DotNetCompilerPlatform,分散注意力的红色涂鸦消失了,导航符号开始工作。

我只能推测,额外的引用是在升级期间添加的,因为我认为这个项目最初是在Visual Studio 2015中创建的。

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

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.

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

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

和禁用和重新启用ReSharper:

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

REM DELETE ALL VS HIDDEN SOLUTION OPTION FILES
DEL /A:H /S *.SUO