当前的 .NET SDK 不支持面向 .NET Core 2.2。 (SDK 2.2.202)

The current .NET SDK does not support targeting .NET Core 2.2. (SDK 2.2.202)

许多类似问题中的另一个问题,但 none 搜索的解决方案提供了帮助(请参阅下面所查看的解决方案)。

在撰写本文时,.NET Core v2.2 已停止预览,最新版本为 v2.2.202(发布日期,02-04-2019)。

我通过 "Install other frameworks" 安装了那个,我安装了 x64 的,我之前安装的所有其他版本也是那个版本。

安装后,新建项目时,显示:

但是当我打开属性时,它并没有:

dotnet --info 在项目目录中,给出以下结果:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.202
 Commit:    8a7ff6789d

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

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.1.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

我试过:

以上所有尝试当然都涉及重启计算机或重启VS。

这很可能看起来像是 VS 的安装程序优化,它删除了过于贪婪的旧 SDK 并删除了旧 VS 版本所依赖的版本,但目前这更像是一个假设,而 MS 团队正在调查。请参阅 this GitHub issue 了解更多类似报告。

2.2.1xx SDK(!) 版本使用 MSBuild 15,2.2.2xx 使用 MSBuild 16。

VS 2017 需要解析与 MSBuild 15 兼容的本地版本,因此如果在升级过程中删除了 2.2.1xx,这可能会失败。

您可以通过重新安装兼容版本来解决此问题 - 例如2.2.105 - 来自 https://dotnet.microsoft.com/download/dotnet-core/2.2

为了找出哪个 SDK 使用了哪些组件,您可以检查 DependencyVersions.props file in the <3.0 sources and the Versions.props 文件中的 >= 3.0(预览)源 - MSBuild 版本是通过 MicrosoftBuildPackageVersion 属性.

添加来自 https://github.com/aspnet/AspNetCore.Docs/issues/11844 的@martin-ullrich 的回答,因为它对我来说更有意义。 (也许因为今天是星期五,我只需要:"Go here and do this.")

Go to https://dotnet.microsoft.com/download/dotnet-core/2.2 and download the installer for the 2.2.105 version. Anything >= 2.2.200 will not work in VS 2017. Both 2.2.105 and 2.2.202 contain the latest and greatest .NET Core 2.2 version but they differ in the version of the tools they include and are based on - the 1xx train is MSBuild 15., NuGet 4. etc. and the 2xx train is MSBuild 16., NuGet 5. and so on and Visual Studio only looks for the latest version compatible with its version of MSBuild - for VS 2017 this is 2.1.502 version which cannot target .NET Core 2.2. (And to add more confusion, there are now 2.1.6xx versions with VS 2019 tool versions together with the .NET Core 2.1 runtime)

[@]leecow and [@]rowanmiller are working on updating that page regarding VS, also see dotnet/core#2542 and dotnet/sdk#3076 which are about the same problem.


我的贡献: 安装 2.2.105 后,我删除了目录 C:\Program Files (x86)\dotnet\sdk 中名为“2.2.202”的文件夹 and/or C:\Program Files\dotnet\sdk 以便 dotnet --info 现在读取以下内容:

安装 dotnet-sdk-2.2.103-win-x64 修复了问题

如果您想使用 asp.net 核心版本高于 v2.2.100,请使用 Visual Studio 2019 而不是 2017 https://github.com/aspnet/AspNetCore.Docs/issues/11844

如果您使用的是Visual Studio 2017 (v15.9)您需要安装.NET Core SDK版本2.2.108 因为更大的版本仅在 Visual Studio 2019.

中受支持

请参阅下面的 table 以 select 正确下载。

同时检查发布信息和下载链接 here