C# Intellisense in VS Code randomly stopped working today.

huangapple go评论82阅读模式
英文:

C# Intellisense in VS Code randomly stopped working today

问题

关键词仍然被识别,但只有新定义的用户类被识别,命名空间也不被识别,代码运行正常,但像这样编写代码真的很烦人。

尝试了几个小时的一切,甚至到了在 Windows 10 虚拟机上运行的程度,使用新用户进行干净安装的 VS Code(只安装了 C# 和 .NET 扩展工具 for Extension Authors 扩展)以及 .NET 7.0 SDK,但仍然无法工作。

我曾考虑重新在我的主系统上安装 Windows,但既然在虚拟机上也无法工作,那将是毫无意义的,还有其他人也遇到这个问题吗?

英文:

Keywords are still recognized but only new user-defined classes are recognized, using namespaces isn't recognized either, code runs fine but really annoying to code like this.

Tried everything for hours, even to the point of running a Windows 10 VM, with a new user doing a clean install of VS Code (with only the C# and .NET Install Tool for Extension Authors extensions) and .NET 7.0 SDK but still not working.

I was considering re-installing Windows on my main system but seeing as how it's not working on the VM either that would be pointless, anyone else having this problem too?

答案1

得分: 5

问题是由Visual Studio Code C#扩展的版本v2.x.x引起的,该版本与当前的v1.x.x(也称为OmniSharpO#)版本不具备相同的功能集(包括一些前所未有的功能,但也缺少一些功能)。然而,未来的目标是使v2.x.x支持v1.x.x已经支持的功能。

您有四个选项之一:

  1. 保持在v2.0.320或更高版本,并添加一个解决方案文件(请参阅2023-08-05更新部分),其中包括您的项目。
  2. 回退到一个由OmniSharp提供支持的版本(版本号<= v1.x.x)(请参阅原始答案部分)。
  3. 通过转到扩展设置并将dotnet.server.useOmnisharp设置为true,返回OmniSharp(请参阅Github - dotnet/vscode-csharp - 如何使用OmniSharp中的引用)。
  4. 等待未来的v2.x.x版本中的功能完全一致(请参阅2023-08-09更新部分中的链接的Github问题)。

2023-08-09更新

正如starball在下面的评论中指出的以及在Stack Overflow上的帖子中讨论的那样,问题的一般原因是,从版本v2.0.320开始,Microsoft决定切换到新的Roslyn Language Server,而不再使用OmniSharp(通常也称为O#),在此之前的版本中一直在使用(请参阅Github发布-Changelog v2.0.320)。Microsoft因此受到了一些批评(请参阅Visual Studio Magazine),因为这将引入闭源功能。

截至目前,新的v2版本缺少一些OmniSharp版本提供的功能。然而,根据已知问题列表,未来计划在两个版本之间达到功能一致性。

以下是截至2023-08-09已知的问题,基于Github - dotnet/vscode-csharp - v2.0.320中的已知问题

  • 诊断相关功能请求和改进#5951
  • [O#一致性] FixAll支持代码修复和重构#5735
  • [O#一致性] Nuget还原#5725
  • [O#一致性] 支持加载没有解决方案文件的项目/文件#5722
  • [O#一致性] 一些csproj项目将无法正确加载#5721
  • [O#一致性] 在上下文中运行和调试测试#5719
  • 从.csproj和.sln中进行调试#5876

请注意,问题#5722 - [O#一致性]支持加载没有解决方案的项目/文件解决了在此处遇到的问题。

因此,正如我之前的答案中所概述的,您有以下几种可能性:

  1. 保持在v2.0.320或更高版本,并添加一个包括您的项目的解决方案文件(请参阅2023-08-05更新部分)。
  2. 回退到一个由OmniSharp提供支持的版本(版本号<= v1.x.x)(请参阅原始答案部分)。
  3. 通过转到扩展设置并将dotnet.server.useOmnisharp设置为true,返回OmniSharp(请参阅Github - dotnet/vscode-csharp - 如何使用OmniSharp中的引用)。
  4. 等待未来版本中的功能一致性(请参阅链接的Github问题)。
英文:

TL;DR

The issues is caused by v2.x.x of the Visual Studio Code C# extension which does not have the same set of features (includes some unprecedented features, but also lacks some features) as the current v1.x.x (= OmniSharp or O#) versions. The goal in the future however is for v2.x.x to support what v1.x.x has already been supporting.

You have one of four options:

  • Stay on >= v2.0.320 and add a solution file (see section Update 2023-08-05) which includes your project
  • Revert back to a OmniSharp powered version (versions <= v1.x.x) (see section Original answer)
  • Go back to OmniSharp by going to the Extension settings and setting dotnet.server.useOmnisharp to true. Next, uninstall or disable C# Dev Kit. Finally, restart VS Code for this to take effect. (quoted from Github - dotnet/vscode-csharp - How to use OmniSharp)
  • Wait for the feature parity to come in future v2.x.x versions (see linked Github issues in section Update 2023-08-09)

Update 2023-08-09

As pointed out in the comments below by starball and the thread What changed about the C# extension for VS Code's IntelliSense in the v2.0.320 release? on SO the general issue is that with versions >= v2.0.320 Microsoft has decided to switch to the new Roslyn Language Server instead of using OmniSharp (also often referred to as O#) which it has been using for versions prior to that (See Github Releases - Changelog v2.0.320). Microsoft did get some heat for that (see Visual Studio Magazine) as this will introduce closed-source functionality.

The new v2, as of now, lacks some features the OmniSharp versions provided. Looking at the list of known issues there are however plans to reach a feature parity between the two versions in the future.

Here the known issues as of 2023-08-09 based on Github - dotnet/vscode-csharp - Known Issues in v2.0.320:
> - Diagnostics related feature requests and improvements #5951
> - [O# Parity] FixAll support for code fixes and refactorings #5735
> - [O# Parity] Nuget restore #5725
> - [O# Parity] Support loading projects/files without a solution file #5722
> - [O# Parity] Some csproj projects will not correctly load #5721
> - [O# Parity] Run and debug tests in context #5719
> - Debug from .csproj and .sln #5876

Note that issue #5722 - [O# Parity] Support loading projects/files without a solution addresses the problem faced here.

With that being said, you have the possibilites as outlined in my previous answers:

  • Stay on >= v2.0.320 and add a solution file (see section Update 2023-08-05) which includes your project
  • Revert back to a OmniSharp powered version (versions <= v1.x.x) (see section Original answer)
  • Go back to OmniSharp by going to the Extension settings and setting dotnet.server.useOmnisharp to true. Next, uninstall or disable C# Dev Kit. Finally, restart VS Code for this to take effect. (quoted from Github - dotnet/vscode-csharp - How to use OmniSharp)
  • Wait for the feature parity to come in future versions (see linked Github issues)

Update 2023-08-05

It seems the issue only occurs if you have a project which is not listed in a solution file, so you can create a solution file e.g. using dotnet new sln --name &lt;solution name&gt; and then add the project(s) to that solution using dotnet sln add &lt;project path&gt;.

It is working with the new version v2.0.328 (released today 2023-08-05) for me when I have all my projects added to a solution file.

Original answer

I've faced the same issue today (2023-08-04). This is due to an update of the extension to v2.0.320. You can fix this by reverting back to version v1.26.0.

You can revert using the UI by going to Extensions -&gt; C# -&gt; Install Another Version:
C# Intellisense in VS Code randomly stopped working today.

There also is an open Github issue related to this.

huangapple
  • 本文由 发表于 2023年8月4日 21:01:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定