使用 Visual Studio 2017 与 .Net Core SDK 3.0

Use Visual Studio 2017 with .Net Core SDK 3.0

如何在 Visual Studio 2017 年打开 .Net Core 3.0 项目?

我已经从 dotnet.microsoft.com 下载了 .NET Core 3.0 SDK,并在文件夹中使用 dotnet new 命令创建了新项目。

构建 C# 项目显示错误:

The current .NET SDK does not support targeting .NET Core 3.0. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.0.

我检查过了,但它对我的情况不起作用:

Visual Studio 2017 with .Net Core SDK 2.1

.Net Core 3.0 需要 Visual Studio 2019 Preview 1,不能使用 Visual Studio 2017。根据 .Net Blog,"Visual Studio 2019 will be the release to support building .NET Core 3 applications" 并且需要 .Net 4.8

创建新的 application/project 时,项目通过 netcorepp3.0 目标框架声明对 .Net Core 3.0 的依赖。

。在 VS 2017 中:您可以转到 工具选项项目和解决方案.NET Core 然后勾选 Use previews of the .NET Core SDK

要创建或打开面向 .NET Core 3.0 的应用程序,需要 Visual Studio2019 或更高版本。 创建新项目时 Visual Studio 可能会显示一个黄色条,其中包含消息 "ASP.NET Core 3.0 or newer projects are not supported by this version of Visual Studio"

更多信息: https://github.com/aspnet/Tooling/blob/master/dotnet-core-3.0-preview1.md

您需要从

启用“使用.NET Core SDK的预览”

Visual Studio's tools | Options | Project and Solutions | .NET Core


此后需要重启visual studio即可使用“.NET Core 3”项目

您也可以关注 youtube page 以获取有关“.NET Core 3”的任何进一步查询。

不幸的是,.NET Core 3 需要 MSBuild 16。即使您按照其他人的建议在 VS 2017 中启用 .NET Core 的预览版,您仍然会收到错误消息:

The current .NET SDK does not support targeting .NET Core 3.0. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.0.

如果您创建一个 global.json 文件并放入例如

{
  "sdk": {
    "version": "3.0.100-preview5-011568"
  }
}

然后你会看到真正的问题是:

error : Version 3.0.100-preview5-011568 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.9.21.664. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.`

MSBuild 16 仅随 VS 2019 一起提供,因此,答案是您可以将 VS 2017 与 .NET Core 3 一起使用,但前提是您还安装了 VS 2019!

这在最新的 vs 预览版中已修复。按照此处的步骤安装它。 https://docs.microsoft.com/en-us/visualstudio/mac/install-preview?view=vsmac-2019

Visual Studio 2019 更新

关于@GoDev 的原始答案:

Starting with Visual Studio 2019, the option has moved to:

Tools > Options > Environment > Preview Features

Official notes

遇到了同样的问题,this 文章帮助解决了问题

1。检查是否安装了 .NET Core SDK 3.x

如果有none,请到.NET Core 3官方下载页面获取,然后安装再试。 https://dotnet.microsoft.com/download/dotnet-core/3.0

2。启用 .NET Core SDK 预览

.NET Core 3.0 preview1 是与 Visual Studio 15.9(又名 Visual Studio 2017)一起使用的 .NET Core 3.0 的最后一个版本:.NET Core 3.0 的任何后续版本(包括 nightlies)需要 VS 16.0+,又名 Visual Studio 2019.

3。检查 PATH 环境变量

参考:https://www.ryadel.com/en/current-net-sdk-not-support-net-core-3-0-fix/

如果您来自未来并且没有特定理由留在 2017 年,升级到 2019 将解决此问题。

安装 .net 核心 2.0。 visual studio 2017 for .net core 适用于版本 2.0、1.1 和 1.0