vscode omnisharp intellisense 不适用于 dotnet 5.0(目标 net5.0)

vscode omnisharp intellisense not working with dotnet 5.0 (target net5.0)

VsCode Omnisharp 不会加载针对 net5.0 的项目。一切似乎都适用于针对较低版本 SDK 的项目。 Omnisharp 加载项目失败,出现以下错误:

“未找到 .NETFramework 的参考程序集,Version=v5.0。要解决此问题,请为此框架版本安装 Developer Pack (SDK/Targeting Pack) 或重新定位您的应用程序。您可以在 https://aka.ms/msbuild/developerpacks"

下载 .NET Framework 开发包

据我所知,5.0 没有“Developer Pack”,所以我不知道该怎么做。然而,Omnisharp 似乎是唯一的问题。该项目将构建 运行 而不会出现错误。我想这意味着 MSBuild 正在寻找框架。 Omnisharp 扩展是 v1.23.8.

Omnisharp 日志中的相关部分和错误:

Starting OmniSharp server at 1/10/2021, 5:49:52 PM
    Target: c:\Users\User Name\Documents\MyProject\Code\test3

OmniSharp server started.
    Path: c:\Users\User Name\.vscode\extensions\ms-dotnettools.csharp-1.23.8\.omnisharp.37.6-beta.23\OmniSharp.exe
    PID: 7580

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Community 2019 16.7.30406.217 - "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin"
            2: StandAlone 16.8.0 - "c:\Users\User Name\.vscode\extensions\ms-dotnettools.csharp-1.23.8\.omnisharp.37.6-beta.23\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Community 2019 16.7.30406.217 - "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin"
...

[fail]: OmniSharp.MSBuild.ProjectLoader
        The reference assemblies for .NETFramework,Version=v5.0 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 'c:\Users\User Name\Documents\MyProject\Code\test3\test.web\test.web.csproj'.

这是我的 dotnet --info 输出:

.NET SDK (reflecting any global.json):
 Version:   5.0.100     
 Commit:    5044b93829  

Runtime Environment:    
 OS Name:     Windows   
 OS Version:  10.0.18363
 OS Platform: Windows   
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  2.2.104 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.1.201 [C:\Program Files\dotnet\sdk]
  3.1.401 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

您的 PC 上安装了 Visual Studio,它是 16.7,OmniSharp 正在尝试使用它的构建工具来启动,但它不是支持 .NET 5.0 的 16.8。只需将 VS 更新到最新版本,一切都会如您所愿。