为什么我的 vscode 1.38.1 在 Ubuntu 19 上打开 .NET Core 3.0 裸控制台应用程序时显示 'predefined type not defined or imported'

Why is my vscode 1.38.1 showing 'predefined type not defined or imported' when opening .NET Core 3.0 bare console app on Ubuntu 19

我安装了 .NET core 3.0 SDK 并使用 dotnet new console 创建了一个控制台应用程序。这是项目文件。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>
</Project>

应用成功运行 dotnet run。当我用Visual Studio代码打开时,ProgramvoidstringConsole等所有类型都有下划线提示错误。错误总是一样的。此示例显示 string 错误

Predefined type 'System.String' is not defined or imported (CS0518) [myproject]

我试过:

请注意,.netcoreapp2.2 应用可以正常打开。

这是一些环境信息:

$ code --version
1.38.1
b37e54c98e1a74ba89e03073e5a3761284e3ffb0
x64
$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  19.04
 OS Platform: Linux
 RID:         ubuntu.19.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  95a0a61858

.NET Core SDKs installed:
  2.2.402 [/usr/share/dotnet/sdk]
  3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.04
Release:        19.04
Codename:       disco

更新:

问题似乎在 VS Code 1.39.0 中得到解决,即使在删除 mono-devel 及其依赖项后也是如此

原文:

显然,这是一个 C# 扩展问题。正如 C# Extension fails only for netcoreapp3.0 GA #3289 问题评论所建议的那样,安装 Mono 6.0.0(在 linux 或 Mac 上)可以解决该问题。我可以确认。

here 安装 Mono 6 或者对于 Ubuntu 18.04 及更高版本 运行 以下内容:

sudo apt install gnupg ca-certificates
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt install mono-devel

我放弃了所有其他 dotnet SDK,只留下 3.0.100 可用。 成功了。

Linux 完好,最新 VSCode。