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

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

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


当前回答

我的一个同事今天就遇到了这个问题。我们尝试了这里的许多建议,除了下面描述的解决方案之外,没有一个有效。

问题:

项目构建良好,但智能感知无法识别某些类型,并将特定的使用语句标记为无效。

解决方案:

将“解决方案平台”(在VS 2017中,这是解决方案配置下拉菜单旁边的下拉菜单,具有诸如x86, x64, AnyCPU,混合平台等值)更改为AnyCPU。

项目的平台可能会有所不同,但有些参考可能并不适用于所有平台。

其他回答

下面的解决方案对我很有效

1 -关闭VS

2 -删除。vs文件夹

3 -开VS

4 -构建解决方案

0 -右键单击解决方案和清洁解决方案

1 -关闭VS

2 -删除项目的.suo文件

3 -开VS

4 -构建解决方案

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

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

和禁用和重新启用ReSharper:

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

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

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.

有很多删除SUO /隐藏解决方案文件的答案。

就我而言,这是因为我需要以管理员身份运行Visual Studio才能发布。会用管理权限覆盖那些文件。现在,当作为标准用户运行时,我无法摆脱任何错误。

如果我重新运行在管理模式,我能够解决所有的错误。