C# Intellisense 无法自动运行 VSCode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29975152/
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
Intellisense not automatically working VSCode
提问by MaylorTaylor
I just downloaded Visual Studio Code and my Intellisense is not automatically working.
我刚刚下载了 Visual Studio Code,我的 Intellisense 不能自动工作。
The two settings that control this seem to be set correctly:
控制它的两个设置似乎设置正确:
"editor.quickSuggestions": true,
"editor.suggestOnTriggerCharacters": true,
I do get an Intellisense menu when i start typing and press "CTRL + Space", but this gives me a list of everything and not things specifically for my object.
当我开始输入并按“CTRL + Space”时,我确实得到了一个 Intellisense 菜单,但这给了我所有内容的列表,而不是专门针对我的对象的内容。
What am i doing wrong?
我究竟做错了什么?
采纳答案by Nacimota
Visual Studio Code's more advanced editing features (IntelliSense, refactoring tools, etc.) only work in C# files if you have a project.jsonfile or *.slnfile that VSCode is aware of. Open the folder (i.e. open the Filemenu and click Open Folder...) with the *.slnfile or project.jsonand VSCode will attempt to find all project/solution files in the folder. If there are multiple projects, you may need to select one from the projects button on the right side of the status bar (bottom of the window).
Visual Studio Code 的更高级的编辑功能(IntelliSense、重构工具等)仅适用于 C#文件,前提是您拥有VSCode 知道的project.json文件或*.sln文件。打开文件夹(即打开File菜单并单击Open Folder...)*.sln文件或project.jsonVSCode 将尝试查找文件夹中的所有项目/解决方案文件。如果有多个项目,您可能需要从状态栏右侧(窗口底部)的项目按钮中选择一个。
From the VSCode website:
- Selecting a
project.json-file is opening a DNX-project and VSCode will load that project plus the referenced projects- Selecting a
*.sln-file is opening a MSBuild-project. It will load the referenced*.csproj-projects and sibling or descendantproject.json-files but no other project files that are referenced from the solution file.- Selecting a
folderwill make VSCode scan for*.slnandproject.jsonfiles and VSCode will attempt to load them all.
- 选择一个
project.json-file 正在打开一个 DNX 项目,VSCode 将加载该项目以及引用的项目- 选择一个
*.sln-file 正在打开一个 MSBuild 项目。它将加载引用的-projects*.csproj和同级或后代project.json-files,但不会加载从解决方案文件中引用的其他项目文件。- 选择
folder将使VSCode扫描*.sln和project.json文件,并VSCode将尝试加载它们。


回答by Sam Storie
As of the 0.5 version I have found that I need to close and re-open my working files to get some new intellisense information to start working for my own files. This usually happens after I have a file open that needs to use type information from another file I just created. Until I close and re-open them (within the editor) the intellisense doesn't always work.
从 0.5 版本开始,我发现我需要关闭并重新打开我的工作文件以获取一些新的智能感知信息来开始为我自己的文件工作。这通常发生在我打开一个需要使用我刚刚创建的另一个文件中的类型信息的文件之后。在我关闭并重新打开它们(在编辑器中)之前,智能感知并不总是有效。
Hopefully this is something that'll get fixed as the app matures.
希望随着应用程序的成熟,这会得到解决。
回答by ShahMansoor
Try "Install Extension" from command Pallete - probably if C# intellisense is not there:
从命令 Pallete 尝试“安装扩展” - 可能如果 C# intellisense 不存在:
回答by MungeWrath
I've had some good experiences in C# with this extension so far: https://marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions
到目前为止,我在使用此扩展程序的 C# 中有一些很好的经验:https: //marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions
"This extension traverses up the folder tree to find the project.json or *.csproj and uses that as the parent folder to determine namespaces."
“此扩展程序向上遍历文件夹树以查找 project.json 或 *.csproj,并将其用作父文件夹来确定命名空间。”
回答by Ganesh Kumar Ponnuswamy
Inorder to make the intelligence working, the Visual Studio Code extension OmniSharp should be there along with Mono. When you open a project/solution folder, the OmniSharp gets the project dependencies from either project.json or from the dotnet solution file (if the project/solution created with other versions of visual studio).
为了使智能工作,Visual Studio Code 扩展 OmniSharp 应该与 Mono 一起存在。当您打开项目/解决方案文件夹时,OmniSharp 从 project.json 或 dotnet 解决方案文件(如果项目/解决方案是使用其他版本的 Visual Studio 创建)获取项目依赖项。
So, when you look at the omnisharp's output window after immediately opening the project/ solution folder, you may see the following lines
因此,当您立即打开项目/解决方案文件夹后查看 omnisharp 的输出窗口时,您可能会看到以下几行
Starting OmniSharp server at 2017-9-18 09:26:44
Target: /Users/{username}/Source/{Your Solution Folder}/{Your Solution
file}.sln
OmniSharp server started wth Mono
Path: /Users/{username}/.vscode/extensions/ms-vscode.csharp-1.12.1/.omnisharp/run
PID: 5808
post that, you may see couple of lines coming up like below,
发布后,您可能会看到如下所示的几行,
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
Update project: {Your Project1 Name}
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
Update project: {Your Project2 Name}
....
they mean that your projects are getting recognised by OmniSharp Extension.
它们意味着您的项目得到了 OmniSharp Extension 的认可。
If you get any error message informing you about timeout, please get into the settings of the Visual Studio Code, and add a configuration override like the one below:
如果您收到任何有关超时的错误消息,请进入 Visual Studio Code 的设置,并添加如下所示的配置覆盖:
"omnisharp.projectLoadTimeout": 200
I know it is too long to wait for 200 seconds. But don't worry, this won't stop you anymore working with project files. But, remember that the IntelliSense will be automatically available once all the projects in the folder are successfully loaded.
我知道等待 200 秒太长了。但别担心,这不会阻止您再使用项目文件。但是,请记住,一旦成功加载文件夹中的所有项目,IntelliSense 将自动可用。
Feel free to extend the Timeout setting since it will help you getting intellisense even-though you are not getting it immediately.
随意扩展超时设置,因为它会帮助您获得智能感知,即使您没有立即获得它。
Here is another link with the same solution: https://github.com/OmniSharp/omnisharp-vscode/issues/1585
这是具有相同解决方案的另一个链接:https: //github.com/OmniSharp/omnisharp-vscode/issues/1585
Hope my information helps you! Enjoy your VSCode!
希望我的信息对你有帮助!享受你的 VSCode!
回答by Ryan Hill
Another troubleshooting strategy to try if none of the above works out is uninstalling Mono, which is unnecessary anyways if you're using .NET Core. I also experienced a sudden disappearance of Intellisense after pulling changes to one of our enterprise repos that included an upgrade from ASP.NET Core 2.0 to 2.1. Strangely, at the same time, Intellisense was working fine in another C# project repo running ASP.NET Core 2.2.
如果上述方法均无效,则要尝试的另一种故障排除策略是卸载 Mono,如果您使用的是 .NET Core,则无论如何都不需要。在对我们的一个企业存储库进行更改(包括从 ASP.NET Core 2.0 升级到 2.1)后,我还遇到了 Intellisense 突然消失的情况。奇怪的是,与此同时,Intellisense 在另一个运行 ASP.NET Core 2.2 的 C# 项目存储库中运行良好。
For the project in question, I was puzzled to see successful logs for each reboot of the Omnisharp server as well as perfectly clean builds and runs. The puzzlement increased as I compared these Omnisharp logs to those from the 2.2 project and found them effectively identical.
对于有问题的项目,我很困惑地看到 Omnisharp 服务器每次重新启动的成功日志以及完全干净的构建和运行。当我将这些 Omnisharp 日志与 2.2 项目中的日志进行比较并发现它们实际上相同时,我的困惑增加了。
Upon uninstalling Mono, the one detail that changed is how Omnisharp started. Now it boots up from a shell script located at ~/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/run. Previously, Mono itself was booting the server from the executable at ~/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/omnisharp/Omnisharp.exe.
卸载 Mono 后,发生变化的一个细节是 Omnisharp 的启动方式。现在它从位于~/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/run. 以前,Mono 本身是从~/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/omnisharp/Omnisharp.exe.
Other troubleshooting I attempted in this instance though to no avail:
我在这种情况下尝试的其他故障排除虽然无济于事:
dotnet clean/ Deleting bin and obj directories- Updating
launch.jsonto point at the proper/bin/Debug/netcoreapp2.1build directory - Wiping my local nuget cache
- Restarting Omnisharp
- Uninstalling and reinstalling VS Code, as well as bumping back a version from 1.33.1 as the breakage coincided oddly with the March 2019 update
- Uninstalling and reinstalling the C# VS Code extension, as well as bumping back a version from 1.19.0 given other users' reports of said version interfering with Intellisense for certain projects*
- Adding a
global.jsonfile at project root to override default utilization of latest .NET Core SDK (mine was 2.2.105) and run instead using 2.1.302 in concert with the project's version - Wiping/rebuilding the project
.slnfile
dotnet clean/ 删除 bin 和 obj 目录- 更新
launch.json以指向正确的/bin/Debug/netcoreapp2.1构建目录 - 擦除我的本地 nuget 缓存
- 重启 Omnisharp
- 卸载并重新安装 VS Code,以及从 1.33.1 退回一个版本,因为损坏与 2019 年 3 月的更新奇怪地重合
- 卸载并重新安装 C# VS Code 扩展,以及根据其他用户报告该版本干扰某些项目的 Intellisense*,从 1.19.0 退回版本
global.json在项目根目录添加文件以覆盖最新 .NET Core SDK(我的是 2.2.105)的默认使用,并使用与项目版本一致的 2.1.302 运行- 擦除/重建项目
.sln文件
Specs: VS Code 1.33.1, C# Extension 1.19.0, MacOS High Sierra 10.13.6.
规格:VS Code 1.33.1,C# 扩展 1.19.0,MacOS High Sierra 10.13.6。
*NB: As it turns out, in another.NET Core 2.1 project with the same issues in VS Code as described above, uninstalling Mono alone did not fix things. I also didwind up needing to bump back the C# extension to v. 1.18.0 to recover Intellisense. Weird.
*注意:事实证明,在另一个.NET Core 2.1 项目中,VS Code 中存在与上述相同的问题,单独卸载 Mono 并不能解决问题。我也确实需要将 C# 扩展回滚到 v. 1.18.0 以恢复 Intellisense。奇怪的。
回答by 2b77bee6-5445-4c77-b1eb-4df3e5
This case was for an existing project that was working fine before. Opened via the vs code "recent" history.
此案例适用于之前运行良好的现有项目。通过 vs 代码“最近”历史记录打开。
For dotnet core. I opened my project's *.csprog file, made no changes, and saved it via the vs code editor.
对于 dotnet 核心。我打开了我项目的 *.csprog 文件,没有做任何更改,并通过 vs 代码编辑器保存它。
As soon as I saved, all of the intellisense stuff starting working again in my other files within that project.
我一保存,所有的智能感知内容就会在该项目中的其他文件中再次开始工作。
回答by carlowahlstedt
After trying several things I looked at the OmniSharp logs only to realize that because I had two different sln files in my workspace. It had picked up the “other” one and thus wasn't working. I deleted it, reopened vs code, and all is well again.
在尝试了几件事之后,我查看了 OmniSharp 日志才意识到这是因为我的工作区中有两个不同的 sln 文件。它已经拿起了“另一个”,因此无法正常工作。我删除了它,重新打开 vs 代码,一切又好了。
回答by James L.
For me I had been working without internet for a long time. It had previously been working but then stopped. I closed+reopened VSCode with a stable wifi connection and the Outputtab in VSCode popped up, displaying the the extensions were re-installing. After that it worked!
对我来说,我在没有互联网的情况下工作了很长时间。它以前一直在工作,但后来停止了。我用稳定的 wifi 连接关闭+重新打开 VSCode,并且OutputVSCode 中的选项卡弹出,显示正在重新安装扩展。之后它起作用了!
回答by Henrik
If you have a workspace and for some reason have multiple folders you may need to 'help' omnisharp a bit. I initially had a big project and added a solution for it further on - ending up with TWO workspace folders (one to a startup project and one to the solution). After composing that setup I experienced only the first project to have intellisense working.
如果您有一个工作区并且由于某种原因有多个文件夹,您可能需要“帮助” omnisharp 一点。我最初有一个大项目,并进一步为它添加了一个解决方案 - 最终有两个工作区文件夹(一个用于启动项目,一个用于解决方案)。完成该设置后,我只经历了第一个让智能感知工作的项目。
Solution to get intellisense working was to make sure omnisharp worked its way from the solution instead of the project:
让智能感知工作的解决方案是确保 omnisharp 从解决方案而不是项目中工作:
- Ctrl + shift + p
- Select "OmniSharp: Select Project"
- Choose the solution workspace entry.
- Ctrl + shift + p
- 选择“OmniSharp:选择项目”
- 选择解决方案工作区条目。
Inspiration gotten from 'swaner': https://github.com/OmniSharp/omnisharp-vscode/issues/1889
灵感来自“天鹅”:https: //github.com/OmniSharp/omnisharp-vscode/issues/1889

