33

Error:

C:\WebApp\WebApp.csproj : error : The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. C:\WebApp\WebApp.csproj

I am trying to open Dotnet core project and I am getting the above error.

I have installed the latest SDK from https://www.microsoft.com/net/core#windowscmd

I have checked the path for dotnet cmd and it works fine.

Am I missing something? Let me know if you need more information.

The target framework is set to .NET 4.5.2

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Sundeep
  • 2,035
  • 2
  • 23
  • 38

17 Answers17

27

I stumbled upon this issue a number of times recently. Here's a brief list of the workaround I found (one of them always worked until now):

  1. Install the right .NET Core SDK: Either the latest version or the version required by your project.
  2. Clean-up obsolete .NET Core versions: Go to Control Panel and uninstall previous .NET Core SDK/Runtime versions (as long as you don't use them anymore).
  3. Create a Global.json file: Add a new global.json file to your project's root with the following content (replace the .NET Core version build with the one you want to run the project with):

    { "sdk": { "version": "2.0.5" } }

  4. Rename the SDK reference: Open your .proj file and replace <project sdk="Microsoft.NET.Sdk.web"> with <project sdk="Microsoft.NET.Sdk"> .

  5. Add the MSBuildSDKsPath Environment Variable: The dotnet CLI sets the MSBuildSDKsPath environment variable when invoking MSBuild: however, a December 2016 patch changed the CLI behaviour so that it will respect an existing environment variable, if it has already been set: this will allow the developer to “force” the CLI to use a specific SDK.

  6. Check your PATH: Verify that both C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable.

For additional info regarding the issue and other viable fixes check out this blog post that I wrote on this topic.

Darkseal
  • 9,205
  • 8
  • 78
  • 111
  • Why we need to put both path to environment variable? – dev Jul 27 '18 at 17:08
  • 1
    Still an ongoing issue with Visual Studio 15.8.2. This help sort me out - it was the global.json value. Removing the file didn't help, but updating the version number in it did. – Phil S Aug 30 '18 at 15:17
  • 1
    **Before uninstalling older SDK versions** (step 2), please read [the issues I went through by doing this](https://stackoverflow.com/a/55687337/6225838). – CPHPython Apr 15 '19 at 10:47
  • 1
    In Visual Studio 2019 with Net Core 3.0 preview, I had this issue when I installed only the x64 version. Check https://stackoverflow.com/questions/55741953/getting-netsdk1045-the-current-net-sdk-does-not-support-net-core-3-0-as-a-tar – FranzHuber23 Apr 18 '19 at 08:27
9

I agree with the comment on Sundeep's answer, you shouldn't have a global.json file in your project anymore.

It seems as though installing the .NET Core 2.0 SDK is causing issues with the PATH. Verify that C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable. In my case, these values were already present under System Variables so I added them to User Variables and rebooted my machine. This resolved my issue.

AperioOculus
  • 6,641
  • 4
  • 26
  • 37
  • In my case, I had the 32 bit runtime and the 64 bit SDK installed, the 32 bit (x86) entry was in the PATH before the 64 bit one. After additionally installing the 32 bit SDK, it worked. – MarkusSchaber Dec 07 '17 at 14:08
  • I only had the 64-bit SDK installed, but for some reason I only had the 32-bit entry in the Path setting. I tried installing the 32-bit SDK, but ultimately I just added the 64-bit path ahead of the 32-bit one. – Jim Billig Dec 15 '17 at 15:14
  • I have just renamed my dotnet folder in `C:\Program Files\dotnet` and tried to find what was the problem. Thanks for answer. But also, there is no `dotnet` folder in `C:\Program Files (x86)`. Interestingly. – KaraKaplanKhan Apr 24 '18 at 08:42
8

As suggested in the comment, I updated global.json file as shown below

{
  "sdk": {
  "version": "1.0.0"
 } 
}

Also, I had to remove the <ItemGroup> which contains wwwroot files path in .csproj file.

enter image description here

Reload the project and it works like a charm!

Sundeep
  • 2,035
  • 2
  • 23
  • 38
  • 10
    Removing the global.json is probably the best option assuming you always want the latest sdk. In my case I had a misplaced global.json sitting in a folder above the .net core project (probably got placed there by mistake a long time ago). Once I removed that my projects loaded again. – Per Aug 16 '17 at 19:37
  • 1
    where is global.json in .NET core ? –  Aug 18 '20 at 09:25
6

I've encountered the same problem, I just rename <project sdk="Microsoft.NET.Sdk.web"> to <project sdk="Microsoft.NET.Sdk"> on csproj


another situation: https://stackoverflow.com/a/55529011/2971851

issue details: 2.1.6xx & 2.2.2xx version of the SDKs are only supported on Visual Studio 2019. VS 2017 needs 2.1.5xx & 2.2.1xx versions of the SDK.

How to fix the issue? Install 2.1.5xx version of the SDK if you are targetting a 2.1 app Install 2.2.1xx version of the SDK if you are targetting a 2.2 app.

and according to the official document:

Note: If you are a Visual Studio user, there are MSBuild version requirements so use only the .NET Core SDK supported for each Visual Studio version. If you use other development environments, we recommend using the latest SDK release.

Steven Chou
  • 1,504
  • 2
  • 21
  • 43
3

Do not uninstall previous SDK versions!

When I followed the 2nd step suggested in Darkseal's answer, uninstalling the previous SDK versions, it caused an "expected imports are missing" fatal error every time I opened up my project, so I needed to repair my Visual Studio, since installing the old SDK versions again kept popping up this error...

Also the other steps mentioned in that answer did not make any difference (both dotnet references were present in the environment variables and MSBuildSDKsPath was not needed for me).

Install the proper SDK version and select it in the Solution's Properties

As Jyoten mentioned I was using VS2017 x86 version and my SDKs were x64.

However, this was not the only issue, it seems there's some incompatibility with some SDK versions and VS2017. Having installed SDK v2.2.203 and v2.2.202, they would never showed up in the Target framework dropdown when I double-clicked the Properties on my project's solution (in the Solution Explorer (Ctrl+Alt+L)).

So I needed to install v2.2.105 x86 as mentioned in this answer, for it to show up in that dropdown.

Once it did, the solution that was requiring .NET Core v2.2 worked properly (did the Build normally).

CPHPython
  • 12,379
  • 5
  • 59
  • 71
1

I had this issue when I had to open a .Net Core 1.0.4 project in VS2017.

When I installed 1.0.4 SDK, i chose the x64 version which placed the sdk files in 'c:\Program Files\dotnet' ...

but my VS2017 was 32bit and was therefore looking for the sdk in 'c:\Program Files (x86)\dotnet'.

Once I installed the 32 bit version of the SDK it worked fine.

Jyoten
  • 11
  • 4
  • Thank you for the explanation, this was also my issue. I had to do [further steps though](https://stackoverflow.com/a/55687337/6225838), since [Darkseal's answer](https://stackoverflow.com/a/48848090/6225838) caused me more issues than solved. – CPHPython Apr 15 '19 at 10:41
0

I was running into an issue where creating a new ASP.NET Core 2.0 project was giving me an error The SDK 'Microsoft.Net.Sdk.Web' specified could not be found, and leaving me unable to open the project in Visual Studio. The problem was the project was created in a folder that contained a global.json file, tying the SDK version to 1.0.0.

Deleting the global.json, or updating it to 2.0.0, fixed the issue. Be sure to check parent folders too - if any parent folder contains a global.json, the SDK version specified in the "closest" folder will be used.

user1089766
  • 597
  • 6
  • 14
0

I was getting this error in Visual Studio Code.

I was able to find the issue by setting the OmniSharp log settings in VS Code to debug. Once I did that I could see that it wasn't finding Microsoft.Build.Resources.dll.

I installed MS Build by repairing my VS 2017 Community installation. That fixed it.

user3236794
  • 578
  • 1
  • 6
  • 16
0

uninstall and reinstall microsoft .NET core SDK. then restart visual studio. this works for me.

0

Choose the proper SDK according to your Visual Studio and Operating System. I downloaded the correct version from here https://dotnet.microsoft.com/download/visual-studio-sdks and after that .Net Core appeared in target frameworks list (there is a strict dependence between sdk version and VS version, so be careful).

zeonet
  • 26
  • 3
0

I have solved this issue by, go to this site, https://dotnet.microsoft.com/download In that, install both .NET Core Runtime and .NET Core SDK. After you install that, Open the Visual Studio 2017 with an administrator, Now The problem has been gone

Mei
  • 305
  • 2
  • 7
0

I edited the .csproj file and changed netcoreapp2.2 to netcoreapp2.1 in this stanza & then I was able to get it working.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
James Burnett
  • 151
  • 1
  • 5
0

This worked for me:

  1. Make sure that the .NET folder where SDKs are and Visual Studio are in the same program files (x86) or program files.
  2. Provide the path to the SDK in the environment variable.
rrirower
  • 4,338
  • 4
  • 27
  • 45
Priyanka Arora
  • 409
  • 4
  • 10
0

If anyone else stumbles upon this issue (including future me), I had the same problem and tried literary every solution proposed here and nothing worked. Finally what fixed the issue for me was deleting NuGetFallbackFolder in C:\Program Files\dotnet\sdk.

After deleting that folder, everything just started to work magically.

ibrcic
  • 756
  • 1
  • 6
  • 12
0

I had this error when from old project (in .NET 4.7.2) I was trying to do:

var project = new Microsoft.Build.Evaluation.Project(someDotNet6ProjectPath);

The solution was to upgrade Microsoft.Build packages.

therko
  • 59
  • 4
  • 17
0

Download and install "learn-to-code toolkit".

https://dotnet.microsoft.com/en-us/learntocode

I solved the problem

César Augusto
  • 593
  • 1
  • 7
  • 7