ChatGPT解决这个技术问题 Extra ChatGPT

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

have tried upgrading to the professional version of 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.

When I created a new web application I get an error saying

"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."

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."

I don't see ".net core 2.1" in my target framework

I don't have global.json file in my computer

When I try dotnet --info, I get this

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\2.1.100\ Microsoft .NET Core Shared Framework Host Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

This is bleeding edge stuff, any 15.x.0 VS release is agilely broken by design. The workaround does not smell correct. Pretty important to use Help > Send Feedback > Report a Problem or this won't get fixed soon enough.
"broken by design" == bad design. I get that MS wants to rapidly deploy, but the dependency hell they are reintroducing to the development landscape reminds me of trying trying to build code on linux kernels in the 90's...
It's all explained in stackoverflow.com/questions/67049414/… which is the MS supported answer

s
surfmuggle

The problem here is that Microsoft confused a whole lot of people with how they numbered their .NET Core SDKs.

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).

I came across this post The current .NET SDK does not support targeting .NET Core 2.1 on developercommunity.visualstudio.com where a Microsoft support person explains the confusion:

"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."

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.


"We have determined that this issue is not a bug" I would call this a bug.
"We have determined that this is embarrassing, so we're not going to call it a bug."
- it looks bad.
It's not a bug. it's a huge craziness which cost people some precious time
That answer is not corrects. See stackoverflow.com/questions/67049414/… which is the MS supported answer
S
Stephen Rauch

This happened to me after installing 2.2.100-preview3-009430 and then updating to Visual Studio 15.9.2.

I resolved by enabling the "Use previews of the .NET Core SDK" option.

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.

VS Preview Options


What on a build server which only has "Build tools" installed? There is no GUI there.
Worked for NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.0. when trying out blazor
There is no such option in the VS v.16.1
It was moved to Tools > Options > Environment > Preview Features
D
Dmitry Pavlov

Installing .NET Core SDK 2.1.300-preview2 did the trick for me:

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.

See also this answer when you are getting error like this in general:

The current .NET SDK does not support targeting .NET Core 2.X


My solution builds not but now IIS Express is spitting out this error 'MACHINE/WEBROOT/APPHOST/ORCHARDCORE.CMS.WEB' with physical root 'C:\Projects\OrchardCore\src\OrchardCore.Cms.Web\' failed to start process with commandline 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web Tools\ProjectSystem\VSIISExeLauncher.exe -argFile "C:\Users\daves\AppData\Local\Temp\tmp221C.tmp"', ErrorCode = '0x80004005 : 0.
@DavidSopko most likely you need to take care of environment variables LAUNCHER_PATH and LAUNCHER_ARGS blog.lextudio.com/…
s
surfmuggle

I resolved the problem. the cause was that i installed

aspnetcore-runtime-2.1.0-preview1-final-win-x64 and

.net core SDK 2.1.4-x64 versions.

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.

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

The question VS2017 Update 3 'Microsoft.NET.Sdk.Web' could not be found helped in resolving this issue.


I am facing same issue and installed aspnetcore-runtime-2.1.0-preview1-final-win-x64 probably somewhere last month. I don't remember from where i even installed and could not see even any link now available now for such download (hoping that page might have this issue discussed) From where did you installed x86 version ? Can you add more description to your answer as it seems common issue.
@RahulAgarwal A bit late to the game, but if you still haven't found the right download page, it is: microsoft.com/net/download/windows Click on the x86 download link.
c:\Program Files\dotnet is x64, c:\Program Files(x86)\dotnet is x86. VS is looking in the wrong place because the first installation was x86, which set the first path variable. See stackoverflow.com/questions/67049414/… which is the MS supported answer
G
GirishBabuC

https://www.microsoft.com/net/download/visual-studio-sdks

You can download the SDK from the above site

check the SDK which is in your machine Path C:\Program Files\dotnet\sdk

Change or check the target framework in 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.

https://i.stack.imgur.com/sCbIG.png


I got the OP error after adding a Class Library (.NET Core) project. It turns out the Target framework was not set by default so all I had to do was select it from the drop down and save, problem solved.
j
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:

"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."

The target framework for my project was empty and the dropdown didn't show 2.2.

After installing .NET Core SDK 2.2.103, the error was gone and the dropdown did show ".NET Core 2.2".


R
Rosdi Kasim

Check to make sure you don't have global.json file in your project root folder that forces your project to use .NET SDK 2.1 only.

If you have this global.json file, delete it, and then restart 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


O
Ongun23

Stopping IIS for publishing solved the problem. But first I needed to install net core 2.1 SDK and update the Visual Studio.


s
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.


Does this mean Visual Studio is not using SDK 2.1.401 even when it is installed next to 2.1.301?
T
Tawanda Ziki

I also solved the problem in this way:

Check versions on dotnet sdk available

C:\Users\me>dotnet --list-sdks

 ##2.1.202 [C:\Program Files\dotnet\sdk]
 ##2.1.505 [C:\Program Files\dotnet\sdk]
 ##2.1.508 [C:\Program Files\dotnet\sdk]
 ##2.1.509 [C:\Program Files\dotnet\sdk]
 ##2.1.511 [C:\Program Files\dotnet\sdk]
 ##2.1.514 [C:\Program Files\dotnet\sdk]
 ##2.1.801 [C:\Program Files\dotnet\sdk]

I tested my build on all of those versions and it does not work until I uninstalled all of the above from Programs and Features. Then download from the latest:

https://dotnet.microsoft.com/download/dotnet-core/thank-you/sdk-3.1.300-windows-x64-installer

This worked. Dont waste time like i did just install latest version of dotnet sdk and you good to go. "


A
Ambroise Rabier

I am using Rider, I had

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

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:

Project 'WebApplication3' load failed: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found..

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...

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/

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.

In Rider/Build, Execution, Deployement/Toolset and Build I 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


I'm pretty sure it has to do with the last line of your post: so which MSBuild version Rider is actually using. It must be point to the one provided by the latest .NET Core SDK you want to use; otherwise something is wrong, and you need to reinstall the SDK...
J
Johnny Chu

I started getting this error after I installed SDK 2.2.300. After reading this post and some other I downgrade it to SDK 2.2.1xx and the error went away. Note: I had to uninstall SDK 2.2.300 and restart after installing SDK 2.2.1xx.


P
Paul Lewallen

I had this problem and I did a fresh install of VS2017. That fixed it!


M
Mashal Aman

Go to your pipeline. Click on Edit pipeline. Click on the Agent Specification dropdown. Change it to Windows 2019. Click Save And Queue.

And here you Go. It worked fine for me.


C
Chamila Maddumage

I had the same issue with Visual Studio 2017. Right click on the project and go to the properties. From there you can change the target framework. Choose appropriate framework and run your project. This solution was worked for me.


L
Lance Parkington

It looks like Microsoft are encouraging better coding practice for those early adopters of latest development software in Net Core 2.1 by removing the capability to use older software where bad habits prevail. Net Core 2.0 and the older versions are almost end of life so should not be being used at all. (https://blogs.msdn.microsoft.com/dotnet/2018/06/20/net-core-2-0-will-reach-end-of-life-on-september-1-2018/)

1) Microsoft have removed ServiceLocator since widely considered an anti-pattern resulting in difficult to understand code.

2) To improve MVC applications, the AccountController was removed from Authentication/Authorization to encourage use of Razor pages which implement the Single Responsibiity Principle.

It would not be considered best practice to circumvent these changes in order to increase perpetuation of software built to lower software engineering standards in the past.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now