136

I want to create a class library project with Target Framework .NET Standard 2.0.

I've updated my Visual Studio 2017 to Version 15.3 and also in Visual Studio installer checked .NET Framework 4.7 SDK and .NET Framework 4.7 targeting pack manually and installed them.

There is still no .NET Standard 2.0 option in the Target Framework combo box in the Project/Application window. So I changed TargetFramework tag in .csproj file manually to netstandard2.0, but after trying to build I get this error:

The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.

Lewis Browne
  • 904
  • 7
  • 23
sahar
  • 1,769
  • 3
  • 13
  • 14
  • 5
    Do you have a `global.json` file pinning your .NET Core SDK to 1.x? Have you installed the .NET Core 2.0 SDK separately? (I'd *expect* it to be included with VS, but it wouldn't hurt to install it anyway.) – Jon Skeet Aug 17 '17 at 10:11
  • 1
    @JonSkeet installing .NET Core 2.0 SDK separately worked. It will be good if you add your suggestion as an answer here. – sahar Aug 17 '17 at 10:51
  • 1
    Editing .csproj file and edit .net versions (remove all but net462) may solve this problem. – morteza Nov 05 '22 at 11:50

16 Answers16

158

It sounds like installing the VS2017 update for that specific version didn't also install the .NET Core 2.0 SDK. You can download that here.

To check which version of the SDK you've already got installed, run

dotnet --info

from the command line. Note that if there's a global.json file in either your current working directory or any ancestor directory, that will override which version of the SDK is run. (That's useful if you want to enforce a particular version for a project, for example.)

Judging by comments, some versions of VS2017 updates do install the .NET Core SDK. I suspect it may vary somewhat over time.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • So to target .net Standard 2.0, I need to install .NET Core 2.0 SDK? – Marwie Aug 17 '17 at 16:26
  • 1
    @Marwie: To target netstandard2.0, I suspect you do. I haven't tried targeting that with the 1.0 SDK, but I wouldn't be surprised if it failed. You can still target netstandard1.X with the 1.0 SDK of course. – Jon Skeet Aug 17 '17 at 16:27
  • 7
    Ok - I'm new to the subject - I was surprised about the close relationship between .net core and .net standard - wasn't the reason to create .net standard to omit such dependencies? Why wouldn't it ship in a separate package? – Marwie Aug 17 '17 at 16:29
  • 1
    @Marwie: Well, .NET Core SDK is separate from the .NET Core Runtime, which is separate from the .NET Standard. But the SDK "knows about" a set of target frameworks, and I'm not surprised that it won't work with a *future* one. It's like expecting Visual Studio 2013 to compile C# 7 code. While it would possibly be *feasible* for MS to have engineered it so that you didn't need the .NET Core 2.0 SDK to target netstandard2.0, it would be an odd use case to want that anyway, IMO. – Jon Skeet Aug 17 '17 at 16:37
  • Installing Visual Studio 15.5.1 installs the .Net Core 2.0 SDK, so a manual install is not necessary. – Johnny Oshika Dec 13 '17 at 15:22
  • @JohnnyOshika: Is that installing VS 15.5.1 *from scratch* though, or updating from an earlier VS15.X? – Jon Skeet Dec 13 '17 at 15:28
  • In the *Visual Studio Installer* I had to navigate to *Modify > .NET desktop development (under Summary) > Optional* and to check *.NET Core 2.0 development tools*. (VS 15.5.2) – Olivier Jacot-Descombes Dec 21 '17 at 15:37
  • 3
    I received the error after i uninstalled all the .net Core 1.x SDKs. I still had Microsoft. .NET core SDK 2.0.2, 2.0.3, 2.1.1 and 2.1.2 installed and VS 2017 5.2. Once I did a manual install of the current Microsoft. .NET core SDK (2.1.3) I could again compile my projects. I wonder what in removing the 1.x SDKs broke the 2.x SDKs. – SOHO Developer Dec 22 '17 at 18:52
  • Didn't work for me, I have .NET 2.1.4 and .NET Core 2.0.5 installed and yet I still only have up to .NET Standard 1.6 available in project properties, no .NET Standard 2.0. – Justin Jan 25 '18 at 18:32
  • @Justin: Which precise version of VS are you using? – Jon Skeet Jan 25 '18 at 18:37
  • @JonSkeet 15.5.4. – Justin Jan 25 '18 at 18:43
  • @Justin: Okay, that's very odd then :( I would try creating a 1.x project and then editing the csproj file to target 2.x - if it works, great... and if it doesn't, it'll probably give more information :) – Jon Skeet Jan 25 '18 at 18:56
  • Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='netstandard2.0'. They must be specified explicitly. Common.Emitter C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets 84 – Justin Jan 25 '18 at 19:10
  • @JonSkeet Here is another error that I missed: The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. Common.Contracts C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets 126 – Justin Jan 25 '18 at 19:17
  • 2
    @Justin: Okay, so that sounds like either the 2.1.4 SDK hasn't installed properly, or you've got a global.json file pinning it to an old version. – Jon Skeet Jan 25 '18 at 19:41
  • @JonSkeet You were right, there was a global.json file that was restricting the SDK to a 1.x preview version. Thanks!! – Justin Jan 29 '18 at 15:52
  • I tried updating vs2017 to latest update and this issue has solved. This is because when installing VS2017 for first time, the latest updates were not available at that time. if you update to latest version in "Extensions and Updates", this issue would get resolved. – Viswa Apr 12 '19 at 05:26
28

while the above answers didn't solve my problem. I finally solved it by specifically going to this link https://www.microsoft.com/net/download/visual-studio-sdks and download the required sdk for Visual Studio. It was really confusing and i don't understand why but that solved my problem

Johnny Camby
  • 578
  • 7
  • 11
  • I can't just upvote this, this also resolved my problem too but I hope someone clarifies the reason behind this working. – Beytan Kurt May 07 '19 at 20:13
  • This solution worked for me as well. For me it was a matter of incompatibility with the latest SDK. If you're using Visual Studio 2017, you can't use the latest version of the .NET Core SDK. – zero Aug 28 '19 at 16:26
14

This happens sometimes when I'm trying to open my old projects, what helps me is to change projects target framework. Go to Project -> projectname Properties... and change the Target framework to the one that you have installed. Project properties

H35am
  • 768
  • 2
  • 12
  • 32
12

For me the solution was to change the version in global.json to reflect the installed one.

Like the others said the version can be found running dotnet --info in cmd

This:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "2.0.3"
  }
}

Became:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "2.1.4"
  }
}

You can also create the global.json file by running

dotnet new globaljson --sdk-version 2.1.4

at root of project

Karan Harsh Wardhan
  • 1,096
  • 9
  • 22
lsp
  • 744
  • 6
  • 19
  • 2
    Where would that `global.json` file be found if it would exist? – Bruno Bieri Jul 23 '18 at 09:34
  • I think ms removed that file, check your .sln and .csproj files :) – lsp Jul 24 '18 at 19:03
  • 2
    The file `global.json` would be next to the solution file. I typically have included as a solution item in the solution itself. I found in my experiments that without closing and reloading the solution, changing the version in `global.json` can lead to strange build errors. My comment applies to VS2018, version 15.9.2, with .NET Core SDK 2.2.100. – Manfred Dec 08 '18 at 02:55
  • [From the docs](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json) `.NET Core SDK looks for a global.json file in the current working directory ... or one of its parent directories`. So like an inheritance type file. – StuartLC Jun 06 '19 at 16:15
10

This worked for me

Use the installation of the Visual Studio

On the tab "Workloads" check ".Net Core cross-platform development" and click on "Modify"

enter image description here

Don't forget to check ".NET Core 2.0 development tools" on the left menu.

Source

Note

I installed the Asp Net Core before, however not appeared on my Visual Studio, just after I installed using the installation of Visual Studio appeared for me.

Community
  • 1
  • 1
Wictor Chaves
  • 957
  • 1
  • 13
  • 21
  • 1
    Alternatively, you can install what you need from here: https://dotnet.microsoft.com/download/visual-studio-sdks?utm_source=getdotnetsdk&utm_medium=referral – user2173353 Mar 27 '19 at 11:05
7

I had installations of both Visual Studio 2019 and 2017. I tried installing the .NET Core 2.X SDK for VS2017 separately but with no luck.

The issue is, that I have .NET Core 3.0 SDK installed as default sdk-version, which VS2017 does not like.

My solution was to switch the SDK version for the specific project.

  • First, list your installed SDK's to find the desired version:
$ dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

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

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  1.1.14 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.2.110 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]
  • From your solution directory:
$ dotnet new globaljson --sdk-version 2.2.110 --force

Now, dotnet will use the specified SDK version for this solution.

I have not found a way to do this system-wide without also messing up my 3.0 projects.

J. Doeseph
  • 71
  • 1
  • 4
  • It seems strange that this should be necessary, but greating a global.json (for version 2.1.513) solved my problem too. – 8128 Mar 25 '20 at 11:44
  • I was getting the exact same error but on a MacBook Pro after upgrading to Visual Studio for Mac 2022. Your dotnet command solved it for me. My error message was: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0. – pdschuller Jun 09 '22 at 23:03
3

When I upgraded Visual Studio to version 15.5.1, .Net Core SDK was upgraded to 2.X, so this error went away. When I run dotnet --info, I see the following now:

enter image description here

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
3

I just had this with 15.8.3 after uninstalling some .NET Core 1.x preview SDKs, my application would not compile and showed the error.

It was fixed by installing the latest x86 version of the SDK even though I'm on Windows 10 x64.

I presume this is because VS 2017 is still a x86 program and though the programs run as x64 the compiler was looking for an appropriate x86 SDK

Paul Hatcher
  • 7,342
  • 1
  • 54
  • 51
2

Actually, to me it happened in opposite way to another answers.

I did install the latest .NET Core SDK before the issue appeared (3.0.0-preview2 in my case) having not the latest version of Visual Studio (not sure if that would make any difference).

So, the solution was just to uninstall that latest .NET Core SDK. (This is not perfect if you need it, so you might consider Visual Studio upgrade to the latest one, but at least that solved ongoing issue).

Agat
  • 4,577
  • 2
  • 34
  • 62
2

I had the same problem and I solved this way:

  1. Installed the .NET Core 2.2 SDK for Visual Studio 2017. You can download it from this link: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?utm_source=getdotnetsdk&utm_medium=referral
  2. Went to the project -> Properties > Target Framework

And now I the 2.0 missing target framework was eligible, I selected it and the problem was solved.

1

I just went through this trouble. In my case I had a working script

SET devenvPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe
"%devenvPath%" mySolution.sln /Rebuild "DebugWithUT|AnyCpu" /Out mySolution.Build.log

Today I started getting this exact error. But now I remember installing VS2019 day before. Looks like it changed something for VS2017. I went to VS2017 Update, installed latest version/update and it fixed it back.

T.S.
  • 18,195
  • 11
  • 58
  • 78
1

make sure you download the x86 SDK instead of only the x64 SDK for visual studio.

juFo
  • 17,849
  • 10
  • 105
  • 142
  • This is a duplicate of [an older answer](https://stackoverflow.com/a/52628007/4519059)! – shA.t Nov 02 '22 at 08:57
0

I had same problem, and have the latest ver Microsoft Visual Studio Community 2017 Version 15.7.3

I just downloaded the latest SDK 2.1 and no more targeting issue. https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.301-windows-x64-installer

Info: Microsoft Visual Studio Community 2017 Version 15.7.3 VisualStudio.15.Release/15.7.3+27703.2026 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

C# Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

Visual Basic Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Unity 3.7.0.1 Visual Studio Tools for Unity

  • What is all the additional information for, and where does it come from? Please provide a source and a reason you wrote it all down. – Joachim Mar 15 '23 at 19:07
0

I had the same problem as the current .NET SDK does not support targeting .NET Core 3.1. Either target .NET Core 1.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1

1) Make sure .Net core SDK installed on your machine. Download .NET!

2) set PATH environment variables as below Path

0

I had this issue while trying to build my solution in TFS. We were using "dot net publish" task. Using msbuild broke the ice for us.

0

I fought this problem for days, and what I concluded was that one of my SDK versions was broken.

For example I had 6.0.308 and 6.0.309 installed (in addition to 2.1). What ultimately seemed to fix it was to uninstall (via Add/Remove Programs) 6.0.309, then uninstall 6.0.308 (I had to reinstall it and then remove it -- which I couldn't do with 6.0.309 still installed), then I installed 6.0.310. Not sure exactly which of those worked, but uninstalling/reinstalling the 2.1 versions did not help, only those 6.0 versions.

Mark Sowul
  • 10,244
  • 1
  • 45
  • 51