C++ 在 Visual Studio 中刷新自动完成 (IntelliSense) 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18289936/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:51:14  来源:igfitidea点击:

Refreshing the auto complete (IntelliSense) database in Visual Studio

c++windowsvisual-studio-2010visual-studio-2008

提问by Sebi

I've noticed that the auto complete feature in Visual Studiono longer works properly once my project has reached a certain size (in my case ~4,100 lines of code). I've also noticed that performance also degrades once the number of third-party libraries increases (namespaces and class attributes and methods are no longer visible).

我注意到Visual Studio中的自动完成功能在我的项目达到一定大小后不再正常工作(在我的例子中大约有 4,100 行代码)。我还注意到,一旦第三方库的数量增加(命名空间和类属性和方法不再可见),性能也会下降。

Is there a way of manually updating the auto completion database or create a new one for an existing project?

有没有办法手动更新自动完成数据库或为现有项目创建一个新数据库?

I am currently working under Visual Studio 2008, but I have experienced this issue in Visual Studio 2010as well.

我目前在Visual Studio 2008下工作,但我在Visual Studio 2010中也遇到过这个问题。

回答by Constantin

For VS2015, 2017 and VS2019 close Visual Studio and delete the .vs folder in the same folder as the solution. It contains among other things the intellisense database (it should be possible to delete only the files specific to intellisense, if we knew which ones). Note that if you delete the whole folder you will lose your window layout configurations etc.

对于 VS2015、2017 和 VS2019,请关闭 Visual Studio 并删除解决方案所在文件夹中的 .vs 文件夹。其中包含智能感知数据库(如果我们知道哪些文件,应该可以只删除特定于智能感知的文件)。请注意,如果您删除整个文件夹,您将丢失窗口布局配置等。

For previous versions, close Visual Studio and navigate to your project folder. The *.sdf file there contains the intellisense database- if you delete this files and reopen your project in visual studio, it rebuilds the cache.

对于以前的版本,关闭 Visual Studio 并导航到您的项目文件夹。那里的 *.sdf 文件包含智能感知数据库 - 如果您删除此文件并在 Visual Studio 中重新打开您的项目,它会重建缓存。

Deleting the sdf file solved the problem for me.

删除 sdf 文件为我解决了这个问题。

Sometimes working with a big solution (mainly C++ projects) becomes unbearably slow. To fix it you need to close the solution and go delete the .SDF file. After that it returns to normal again, for about a week, or so until you need to do it again.

The underlying cause is that the SDF file gets fragmented and, according to xperf profiling I've done, VS will sometimes do 20,000+ random reads from it when changing between debug and release. Putting the SDF files on an SSD fixes the problem but should not be necessary. VS needs to use the SDF file more efficiently and not do blocking SDF operations, ever.

有时使用大型解决方案(主要是 C++ 项目)会变得非常缓慢。要修复它,您需要关闭解决方案并删除 .SDF 文件。之后它会再次恢复正常,大约一周左右,直到您需要再次这样做。

根本原因是 SDF 文件变得碎片化,并且根据我所做的 xperf 分析,VS 在调试和发布之间切换时有时会从中进行 20,000 多次随机读取。将 SDF 文件放在 SSD 上可以解决问题,但不是必需的。VS 需要更有效地使用 SDF 文件,永远不要进行阻塞 SDF 操作。

Source: https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2255455-fix-the-delete-sdf-file-problem

来源:https: //visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2255455-fix-the-delete-sdf-file-problem

回答by Goodies

In VS2017 I often run into this situation when I use interop to call CPP from C#, when something is changing on the CPP side.. e.g. constructor arguments.

在 VS2017 中,当我使用互操作从 C# 调用 CPP 时,当 CPP 端发生某些变化时,我经常遇到这种情况......例如构造函数参数。

Unload and reload the CPP project in the solution helps to solve the red lines..

解决方案中卸载并重新加载CPP项目有助于解决红线..

回答by Andy Braham

I am using Visual Studio 2019 and have also been experiencing problems with Intellisense along with other features. I would be able to get through about 2 or 3 updates to a file before Intellisense stopped working along with code formatting.

我正在使用 Visual Studio 2019,并且也遇到了 Intellisense 以及其他功能的问题。在 Intellisense 停止与代码格式化一起工作之前,我将能够对文件进行大约 2 或 3 次更新。

The only way I was able to get things working again was to restart Visual Studio, I tried removing both the intellisense folder and the whole .vsfolder but this didn't solve the problem, it helped but something else was going on.

我能够重新开始工作的唯一方法是重新启动 Visual Studio,我尝试删除智能感知文件夹和整个.vs文件夹,但这并没有解决问题,它有所帮助,但其他事情正在发生。

I was finally able to fix this by turning off the Track changesoption under

我终于能够通过关闭下面的Track changes选项来解决这个问题

Tools->Options->Text Editor->General.

Tools->Options->Text Editor->General.

enter image description here

在此处输入图片说明

回答by Aidan

For Visual Studio 2017 (and I think Visual Studio 2019 also), close Visual Studio, go into the .vs folder in your projects folder and delete all the contents apart from the .suo file, then reopen Visual Studio.

对于 Visual Studio 2017(我认为也是 Visual Studio 2019),关闭 Visual Studio,进入项目文件夹中的 .vs 文件夹并删除除 .suo 文件之外的所有内容,然后重新打开 Visual Studio。

This way you can rebuild the Intellisense cache without losing your preferences.

通过这种方式,您可以重建 Intellisense 缓存而不会丢失您的首选项。