【问题标题】:VSCode autocompletion for C# on UbuntuUbuntu 上 C# 的 VSCode 自动补全
【发布时间】:2021-04-06 19:38:09
【问题描述】:

我正在尝试设置一个环境以在我的 Ubuntu 20.04 计算机上编写 Unity 项目。

我想使用 VSCode 来编写我的 C# 代码。根据需要,我安装了 .NET SDK 5.0.201。

所以,我尝试运行一些代码,但 VSCode 似乎无法识别我的 .NET 安装。每次打开 VSCode 时,都会收到以下消息:

The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path.

而且(主要问题),我的 C# 代码没有自动完成功能。

我真的不明白这里有什么问题。 .NET 在我的终端中被正确识别(ubuntu 终端和 VSCode 中的终端)

>> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.201
 Commit:    a09bd5c86c

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /snap/dotnet-sdk/116/sdk/5.0.201/

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  5.0.201 [/snap/dotnet-sdk/116/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.4 [/snap/dotnet-sdk/116/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.4 [/snap/dotnet-sdk/116/shared/Microsoft.NETCore.App]

我在这里错过了什么?

编辑

C# 扩展也无法加载,并给我以下消息:

The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/path/to/my/project/Assembly-CSharp.csproj'.
/path/to/my/project/Assembly-CSharp.csproj
/home/me/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.6/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1180,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

【问题讨论】:

  • 为了自动完成,安装额外的扩展,比如 Roslynator。
  • 嗯,我确实安装了一些扩展,但由于我遇到的问题,它们似乎无法加载
  • 你安装C# for Visual Studio Code了吗?
  • 是的,这是我安装的扩展。我在启动 VSCode 时使用此扩展程序给我的日志消息编辑了帖子
  • 我不隶属于 jetbrains,但我强烈推荐 Linux 上的 Rider。它比omnisharp + vscode好1000倍。有时它甚至比 Windows 上的 Visual Studio 还要好。

标签: c# visual-studio-code


【解决方案1】:

我终于找到答案了!

在VSCode设置中,我配置了

"omnisharp.useGlobalMono": "always"

代替

"omnisharp.useGlobalMono": "auto"

它成功了

【讨论】:

    猜你喜欢
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    相关资源
    最近更新 更多