当前的 .NET SDK 不支持面向 .NET Core 2.1。面向 .NET Core 2.0 或更低版本,或使用支持 .NET Core 2.1 的 .NET SDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49171623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a .NET SDK that supports .NET Core 2.1
提问by user8559109
have tried upgrading to the professional version of visual studio 2017 v 15.6.0 (Preview 7.0)
已尝试升级到专业版visual studio 2017 v 15.6.0 (Preview 7.0)
and installed aspnetcore-runtime-2.1.0-preview1-final-win-x64 and .net core SDK 2.1.4.
并安装了 aspnetcore-runtime-2.1.0-preview1-final-win-x64 和 .net core SDK 2.1.4。
When I created a new web application I get an error saying
当我创建一个新的 Web 应用程序时,我收到一条错误消息
"The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1."
“当前的 .NET SDK 不支持面向 .NET Core 2.1。要么面向 .NET Core 2.0 或更低版本,要么使用支持 .NET Core 2.1 的 .NET SDK 版本。”
When I try to build an existing project I get an error
当我尝试构建现有项目时出现错误
"The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1."
“当前的 .NET SDK 不支持面向 .NET Core 2.1。要么面向 .NET Core 2.0 或更低版本,要么使用支持 .NET Core 2.1 的 .NET SDK 版本。”
I don't see ".net core 2.1" in my target framework
我在目标框架中没有看到“.net core 2.1”
I don't have global.json file in my computer
我的电脑中没有 global.json 文件
When I try dotnet --info, I get this
当我尝试 dotnet --info 时,我得到了这个
c:\source\dnacloud\testapp>dotnet --info .NET Command Line Tools (2.1.100)
Product Information: Version: 2.1.100 Commit SHA-1 hash: b9e74c6 Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk.1.100\ Microsoft .NET Core Shared Framework Host Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54
c:\source\dnacloud\testapp>dotnet --info .NET 命令行工具 (2.1.100)
Product Information: Version: 2.1.100 Commit SHA-1 hash: b9e74c6 Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk.1.100\ Microsoft .NET Core Shared Framework Host Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54
回答by Cristian Satnic
The problem here is that Microsoft confused a whole lot of people with how they numbered their .NET Core SDKs.
这里的问题是,微软混淆了很多人,他们对 .NET Core SDK 的编号方式感到困惑。
In the original poster's message the path C:\Program Files\dotnet\sdk\2.1.100\ DOES NOT appear to represent the .NET Core 2.1 runtime (but you'd think it does).
在原始海报的消息中,路径 C:\Program Files\dotnet\sdk\2.1.100\ 似乎并不代表 .NET Core 2.1 运行时(但您会认为它确实如此)。
I came across this post The current .NET SDK does not support targeting .NET Core 2.1on developercommunity.visualstudio.com where a Microsoft support person explains the confusion:
我在 developercommunity.visualstudio.com 上看到了这篇文章当前 .NET SDK 不支持针对 .NET Core 2.1,其中 Microsoft 支持人员解释了混淆:
"Thank you for your feedback! We have determined that this issue is not a bug. The first SDK with .NET Core 2.1 support is 2.1.300-preview1. We know the versioning is confusing which is why starting in 2.1.300, the major.minor versions of the SDK will now be aligned with the major.minor versions of the runtime as well."
“感谢您的反馈!我们已确定此问题不是错误。第一个支持 .NET Core 2.1 的 SDK 是 2.1.300-preview1。我们知道版本控制令人困惑,这就是为什么从 2.1.300 开始, SDK 的主要.次要版本现在也将与运行时的主要.次要版本保持一致。”
So ... in order to get .NET Core 2.1 support for building via the SDK you need to install the SDK with version 2.1.300 at least (since 2.1.2 is NOT .NET Core 2.1) ... yeah, confusing. Thank you Microsoft for some lost time on this.
所以...为了通过 SDK 获得 .NET Core 2.1 支持,您至少需要安装 2.1.300 版本的 SDK(因为 2.1.2 不是 .NET Core 2.1)...是的,令人困惑。感谢微软在这方面浪费了一些时间。
回答by Dan Korycinski
This happened to me after installing 2.2.100-preview3-009430 and then updating to Visual Studio 15.9.2.
这发生在我安装 2.2.100-preview3-009430 然后更新到 Visual Studio 15.9.2 之后。
I resolved by enabling the "Use previews of the .NET Core SDK" option.
我通过启用“使用 .NET Core SDK 的预览”选项解决了这个问题。
Go to: Tools > Options > Projects and Solutions > .NET Core
Check the "Use previews of the .NET Core SDK" box
Restart Visual Studio and rebuild the solution.
转到:工具 > 选项 > 项目和解决方案 > .NET Core
选中“使用 .NET Core SDK 的预览”框
重新启动 Visual Studio 并重建解决方案。
回答by Dmitry Pavlov
Installing .NET Core SDK 2.1.300-preview2did the trick for me:
安装.NET Core SDK 2.1.300-preview2对我有用:
UPDATE: just in case, there is a newer version has been released recently. You can download the new .NET Core SDK for 2.2.0-preview1 (which includes ASP.NET 2.2.0-preview1) here.
更新:以防万一,最近发布了一个更新的版本。您可以在此处下载适用于 2.2.0-preview1(包括 ASP.NET 2.2.0-preview1)的新 .NET Core SDK 。
See also this answerwhen you are getting error like this in general:
当您遇到这样的错误时,另请参阅此答案:
The current .NET SDK does not support targeting .NET Core 2.X
当前的 .NET SDK 不支持面向 .NET Core 2.X
回答by user8559109
I resolved the problem. the cause was that i installed
我解决了这个问题。原因是我安装了
aspnetcore-runtime-2.1.0-preview1-final-win-x64and.net core SDK 2.1.4-x64versions.- The installation placed the sdk files in
c:\Program Files\dotnet - but VS2017 32bit was looking for the sdk files in
c:\Program Files(x86)\dotnet.
aspnetcore-runtime-2.1.0-preview1-final-win-x64和.net core SDK 2.1.4-x64版本。- 安装将 sdk 文件放在
c:\Program Files\dotnet - 但是 VS2017 32bit 正在寻找 .sdk 文件
c:\Program Files(x86)\dotnet。
To resolve this i
为了解决这个问题,我
installed the x86 version of the sdk and aspnetcore runtime,
set the MSBuildSDKsPath environmental variable to point to the new installation path.
deleted all obsolete sdks from control panel
安装了 x86 版本的 sdk 和 aspnetcore 运行时,
将 MSBuildSDKsPath 环境变量设置为指向新的安装路径。
从控制面板中删除了所有过时的 sdk
The question VS2017 Update 3 'Microsoft.NET.Sdk.Web' could not be foundhelped in resolving this issue.
找不到问题VS2017 Update 3 'Microsoft.NET.Sdk.Web'有助于解决此问题。
回答by GirishBabuC
https://www.microsoft.com/net/download/visual-studio-sdks
https://www.microsoft.com/net/download/visual-studio-sdks
You can download the SDK from the above site
你可以从上面的站点下载SDK
check the SDK which is in your machine Path C:\Program Files\dotnet\sdk
检查您机器路径 C:\Program Files\dotnet\sdk 中的 SDK
Change or check the target framework in visual studio,
在visual studio中更改或检查目标框架,
Right click on Startup Application or project => Application => Target Framework.
右键单击启动应用程序或项目 => 应用程序 => 目标框架。
You can change the framework and build the solution and restore nugget packages.
您可以更改框架并构建解决方案并恢复块金包。
回答by jamie
Same happened to me, but then for version 2.2 of .NET Core. I installed the latest version of .NET Core 2.2 SDK, which was 2.2.202 at that time. Visual studio allowed me to create a new project for Core 2.2, but it was showing the error:
我也遇到了同样的情况,但随后是 .NET Core 2.2 版。我安装了最新版本的 .NET Core 2.2 SDK,当时是 2.2.202。Visual Studio 允许我为 Core 2.2 创建一个新项目,但它显示了错误:
"The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2."
“当前的 .NET SDK 不支持以 .NET Core 2.2 为目标。要么以 .NET Core 2.1 或更低版本为目标,要么使用支持 .NET Core 2.2 的 .NET SDK 版本。”
The target framework for my project was empty and the dropdown didn't show 2.2.
我的项目的目标框架是空的,下拉菜单没有显示 2.2。
After installing .NET Core SDK 2.2.103, the error was gone and the dropdown did show ".NET Core 2.2".
安装 .NET Core SDK 2.2.103 后,错误消失,下拉菜单显示“.NET Core 2.2”。
回答by Ongun23
Stopping IIS for publishing solved the problem. But first I needed to install net core 2.1 SDK and update the Visual Studio.
停止 IIS 进行发布解决了这个问题。但首先我需要安装 net core 2.1 SDK 并更新 Visual Studio。
回答by sanfalero
I had the .Net Core SDK 2.1.4 installed and followed the other answers in this post without solving my problem. What finally did it for me was installing .Net Core SDK version 2.1.301, and uninstalling every other version. Seems like the SDK 2.1.4 cannot target .Net Core 2.1 but SDK 2.1.301 does the job.
我安装了 .Net Core SDK 2.1.4 并遵循了这篇文章中的其他答案,但没有解决我的问题。最终为我做的是安装 .Net Core SDK 版本 2.1.301,并卸载所有其他版本。似乎 SDK 2.1.4 无法针对 .Net Core 2.1,但 SDK 2.1.301 可以完成这项工作。
回答by Ambroise Rabier
I am using Rider, I had
我正在使用 Rider,我有
The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2
当前的 .NET SDK 不支持面向 .NET Core 2.2。以 .NET Core 2.1 或更低版本为目标,或使用支持 .NET Core 2.2 的 .NET SDK 版本
I had:
我有:
$ dotnet --list-sdks
2.1.2 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
I tried keeping only the latest sdk, and had:
我尝试只保留最新的 sdk,并且有:
Project 'WebApplication3' load failed: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found..
项目“WebApplication3”加载失败:找不到指定的 SDK“Microsoft.NET.Sdk.Web”。
So I removed everything and reinstalled 2.1.602. Made a new project from Rider. And it worked. Cannot say I understood how I solved it...
所以我删除了所有内容并重新安装了 2.1.602。从 Rider 制作了一个新项目。 它奏效了。不能说我明白我是如何解决它的......
The issues for some peoples seems to be linked to global.json, see:
- https://docs.microsoft.com/fr-fr/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio
- https://docs.microsoft.com/fr-fr/dotnet/core/tools/global-json
- https://andrewlock.net/the-sdk-microsoft-net-sdk-web-specified-could-not-be-found/
某些人的问题似乎与 global.json 有关,请参阅:
- https://docs.microsoft.com/fr-fr/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=视觉工作室
- https://docs.microsoft.com/fr-fr/dotnet/core/tools/global-json
- https://andrewlock.net/the-sdk-microsoft-net-sdk-web-specified-找不到/
Other things I did before (that did not seem to solve the issue but might have helped?):
- Updating Rider from 2018.3.2 to 2018.3.4 (latest).
- Installing Mono (was using the one from Unity when look into Rider build settings).
- Tried to use custom MSBuild from Jetbrain (the one used for Linux) without success.
- Installing everything related to .NET Core from VS installer.
- Update VS community ot latest.
- Reboot.
我之前做过的其他事情(似乎没有解决问题,但可能有帮助?):
- 将 Rider 从 2018.3.2 更新到 2018.3.4(最新)。- 安装 Mono(在查看 Rider 构建设置时使用的是 Unity 中的那个)。
- 尝试使用来自 Jetbrain(用于 Linux 的)的自定义 MSBuild,但没有成功。
- 从 VS 安装程序安装与 .NET Core 相关的所有内容。
- 更新 VS 社区 ot 最新。- 重启。
In Rider/Build, Execution, Deployement/Toolset and BuildI now have:
Mono executable: C:\Program Files\Mono\bin\mono.exe
- NET Core CLI executable: C:\Program Files\dotnet\dotnet.exe
- Use MS Build version (Auto detected 16.0): C:\Program - Files\dotnet\sdk\2.1.602\MSBuild.dll
在Rider/Build, Execution, Deployement/Toolset and Build我现在有:
Mono 可执行文件:C:\Program Files\Mono\bin\mono.exe
- NET Core CLI 可执行文件:C:\Program Files\dotnet\dotnet.exe
- 使用 MS Build 版本(自动检测到 16.0):C:\Program - Files\dotnet\sdk\2.1.602\MSBuild.dll
回答by Rosdi Kasim
Check to make sure you don't have global.jsonfile in your project root folder that forces your project to use .NET SDK 2.1 only.
检查以确保您global.json的项目根文件夹中没有强制您的项目仅使用 .NET SDK 2.1 的文件。
If you have this global.json file, delete it, and then restart visual studio.
如果您有这个 global.json 文件,请将其删除,然后重新启动 Visual Studio。
As embarrassing as it might sound, I spent almost an hour tinkering and I even downloaded several SDK version to force it to use 2.2
听起来很尴尬,我花了将近一个小时的时间修修补补,我什至下载了几个 SDK 版本来强制它使用 2.2


