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

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

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


当前回答

我发现在Visual Studio 2017中使用Git时经常发生这种情况,在有依赖代码更改的地方切换分支。即使项目将成功构建,错误列表中仍然会有错误。

这些错误通常是名称空间问题和缺少引用,即使库引用存在。

解决:

关闭Visual Studio 删除{sln-root}.vs\SlnName\v15. txt文件。锁文件(隐藏) 重启Visual Studio

其他回答

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

1 -关闭VS

2 -删除。vs文件夹

3 -开VS

4 -构建解决方案

偶尔,我不得不做一个自定义清理,通过检查所有的项目,手动删除“bin”和“obj”文件夹。要在Visual Studio中看到它们,您必须为每个项目启用隐藏文件和文件夹。完成此操作后,重新构建解决方案。

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

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.

对于我的具体案例,它是另一个开发人员合并到主分支中的服务引用。除了语法高亮显示无法解析生成的服务类和源都是红色下划线之外,这是完全正常的。清理、重建、重新启动什么都没有。

我所要做的就是刷新服务引用,而VS设法在幕后将各个部分组合在一起。源代码或生成的文件没有更改。

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

1 -关闭VS

2 -删除项目的.suo文件

3 -开VS

4 -构建解决方案