116

I'm trying to build a solution using msbuild command line and I keep getting this error:

error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

The version of msbuild is the latest from microsoft visual studio 2017 tools. I'm using Windows Server 2012 R2 and the project uses .NET Core 2.0.

This is the command that I'm using:

msbuild.exe /p:Configuration=Release /t:restore C:\Projects\MyProject.sln

Complete log:

    Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
    Build started 9/16/2017 3:09:03 PM.
    Project "C:\Projects\MyProject.sln" on node 1 (restore target(s)).
    ValidateSolutionConfiguration:
      Building solution configuration "Release|Any CPU".
    Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (2) on node 1 (restore target(s)).
    C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
    Done Building Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (restore target(s)) -- FAILED.

    Build FAILED.
    "C:\Projects\MyProject.sln" (restore target) (1) ->
"C:\Projects\Kernel\Kernel.csproj" (restore target) (2) ->
  C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

0 Warning(s)
    11 Error(s)
Luiz Gustavo Maia
  • 1,181
  • 2
  • 7
  • 7
  • My guess would be that the project references that SDK. And in order to build against it, it must be installed. How else could the compiler do typechkes and all the other stuff? – Christopher Sep 16 '17 at 18:57
  • @Christopher I editted the post with complete log. And yes, my project references that SDK, but I'm trying to restore it. – Luiz Gustavo Maia Sep 16 '17 at 19:06
  • As I thought. The compiler can not find the SDK. You need it installed togeher with the Compiler to make a build. Ideally you picked the default location. If not, you might have to edit the project so it looks for the SDK in the proper location. – Christopher Sep 16 '17 at 19:11
  • 1
    But I already installed .NET Core 2.0 SDK. So, do I have to edit the project file or do I need to reinstall .NET Core SDK in the same location that MSBuild is installed? – Luiz Gustavo Maia Sep 16 '17 at 19:19
  • It works now! I used the follow command: `C:\Program Files\dotnet\dotnet.exe msbuild` – Luiz Gustavo Maia Sep 16 '17 at 19:59
  • 1
    If you found the solution, post as answer and accept it. – Lex Li Sep 18 '17 at 23:40

21 Answers21

114

I encountered this error after playing around with .Net Core 2.0 installation and seemingly messing it up. I would get this same error for dotnet restore, dotnet build or dotnet msbuild. Essentially, anything involving .Net Core and msbuild.

The error occurred because the MSBuildSDKsPath environment variable was still pointing to the old .Net Core 1.1 SDK.

To fix the problem, I manually set the MSBuildSDKsPath environment variable to point to 2.0.0's SDK path, which, for me with x64, this was at: C:\Program Files\dotnet\sdk\2.0.0\Sdks.

Basically, if you have Sdk="Microsoft.NET.Sdk" in your .csproj, then a folder with the same name should exist at your MSBuildSDKsPath location.

Sebastian Nemeth
  • 5,505
  • 4
  • 26
  • 36
  • 25
    Thanks, I had to create a new system environment variable as I had no `MSBuildSDKsPath` then I threw the latest sdk paths in there `C:\Program Files\dotnet\sdk\2.1.500\Sdks`. – Razze Nov 23 '18 at 09:48
  • 5
    The error was on our TeamCity build server only. Installing MS Build Tools with .Net Core SDK was not enough. I also had to create the `MSBuildSDKsPath` and set the value to `C:\Program Files\dotnet\sdk\3.1.101\Sdks`. Thank you @Sebastian – KevinM Mar 05 '20 at 10:42
  • I had TeamCity agent running on Windows Server 2008 R2, this worked for me. I did have to restart the machine to get it to recognise the new environment variable – soupy1976 Apr 16 '20 at 11:35
  • 1
    In my case I had to install ".net core build tools". Its on the initial setup screen of the build tools - i usually skip straight to the individual components. – Peter PitLock Apr 23 '20 at 18:23
  • 2
    Using TeamCity here & forgot to install **.NET Core build tools** as part of Visual Studio (MS) Build Tools. Didn't require the path `MSBuildSDKsPath` and thankful because I'm not trying to maintain that on all my build agents. – Jordan Parker Aug 06 '20 at 07:18
  • Setting said build variable (to C:\Program Files\dotnet\sdk\7.0.102\Sdks in my case) helped my building a new project on a fresh JetBrains Rider installation. – Eike Feb 02 '23 at 09:51
  • 1
    Using this solution means you have to change the variable every time you update to a new SDK. Is there a better solution? – Alex bries Mar 28 '23 at 08:53
39

You were probably missing some components when you installed the VS tools

  1. Download and run Build Tools for Visual Studio 2019. (On the VS download page, go to Tools for Visual Studio 2019 and then click download Build Tools for Visual Studio 2019)

  2. Select Modify on Visual Studio Build Tools 2019 or your instance. enter image description here

  3. Select tab Individual components and check .NET Core SDK component enter image description here

Yasel
  • 2,920
  • 4
  • 40
  • 48
12

for me the solution was to set the sdk version in the global.json file: solution items global.json

and specify the correct version which exists in the C:\Program Files\dotnet\sdk folder. The VS installer uninstalled the previous version of .NET Core 3.0.100 and installed new one 3.1.100 so I had to change it from:

{  "sdk": {    "version": "3.0.100"  }}

to

{  "sdk": {    "version": "3.1.100"  }}
pawellipowczan
  • 500
  • 5
  • 11
  • 1
    I had to add that global.json file but after that the error has gone. – Daniel W. Feb 14 '20 at 07:20
  • 7
    Note that the command to create the global.json is `dotnet new globaljson --sdk-version 3.1.100`. See https://learn.microsoft.com/en-us/dotnet/core/tools/global-json – James Skemp Aug 26 '20 at 16:15
  • after doing this, my error has morphed from `The SDK 'Microsoft.NET.Sdk' specified could not be found.` to `The project file cannot be opened. The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed to run. Object reference not set to an instance of an object.` – knocte Aug 22 '23 at 09:54
  • fuck, it was my fault because earlier I had renamed dotnet.exe to dotnetTMP.exe to just do a small test, d'oh! – knocte Aug 22 '23 at 12:18
10

For me updating Visual Studio Build Tools resulted in the 'SDK not found' error.

The solution: run Visual Studio Installer, modify the Visual Studio (Build Tools) installation, and make sure the following workload is selected:

check ".NET build tools"

HyperQuantum
  • 1,532
  • 1
  • 10
  • 12
6

I got this issue in Mac OS and while using docker container and Azure this occurs because docker bash overrides MSBuildSDKsPath so don't change any code just quit and restart your IDE (visual studio Mac) and run it again

Nelcon Croos
  • 71
  • 1
  • 5
4

I started getting this error after installing Visual Studio 2022 in Windows 10, when I opened up my solution. The solution contains a mix of .NET Framework 4.8 and .NET Standard 2.0 projects, and the error was on the .NET Standard 2.0 projects. I had previously Visual Studio 2019 and 2019 Build Tools installed.

The problem was that I had both x86 and x64 of dotnet installed, and both was in my systems PATH environment variable:

C:\Program Files (x86)\dotnet
C:\Program Files\dotnet

I did the following steps to fix this error:

  • Uninstalled VS2019
  • Uninstalled VS2019 Build Tools
  • Removed the x86 path from the environment variable
  • Removed the folder "C:\Program Files (x86)\dotnet" from my computer
  • Restarted VS2022

I think that the important part was to remove x86 from the environment variable. The other steps was just to "clean up".

Marfyy
  • 63
  • 6
  • 1
    I had this issue as well. Just removed "C:\Program Files (x86)\dotnet" from my user and system paths and it compiled after restarting VS. – kaiken Jun 12 '23 at 20:47
2

I got the same issue when I tried to install x64 .Net Core SDK installer. Even the following dotnet --info command shows me that no SDK is found.

So, try to install x86 .Net Core SDK installer. That can help you.

Tim
  • 5,435
  • 7
  • 42
  • 62
Vadzim Papko
  • 142
  • 1
  • 3
1

I had the same problem and found solution here: https://github.com/aspnet/AspNetCore/issues/3624

Solution is to just have x64 or x86 version of sdk/runtime/hosting. If you have both and if you use for example x86 version of dotnet.exe it won't see x64 versions of SDK installed.

Problem usually occures when you install hosting bundle because it includes both x86 and x64. Just uninstall one you don't use.

hex
  • 713
  • 1
  • 11
  • 17
1

To anyone that, like me, run into this issue on Linux and found this thread:

This problem occurs, because your .bashrc config overrides MSBuildSDKsPath environment variable with outdated value (most likely it's a leftover after dotnet package update). To solve this:

  1. Edit ~/.bashrc
  2. Remove the line with MSBuildSDKsPath variable initialization, e.g.

export MSBuildSDKsPath="/opt/dotnet/sdk/2.2.108/Sdks/"

rufus1530
  • 765
  • 4
  • 19
1

If you have previously worked with C# and it somehow stopped working:


For me updating to the latest version (probably of the build tools) with the "Visual Studio Installer" solved the problem.

codewing
  • 674
  • 8
  • 25
  • A Windows 10 update seemed to have caused the issue for me. Updating Visual Studio 2019 using the Installer fixed it. – AJ Dhaliwal Oct 13 '22 at 11:19
1

The issue was occuring for me only when I tried to build the project with dotnet build using VS2022 . MsBuild on the same project was working fine.

What I did was:

  • restore the .net core runtime sdk - I was using 3.1 at the time. enter image description here

  • Add both sdk paths in both Path vars, for the user and system, in that order: enter image description here

  • Delete the MSBuildSDKsPath

P.s. I had this error while trying to run the coverlet coverage analysis

tanuk
  • 498
  • 9
  • 10
0

Maybe you encountered the error after installing .NET core SDK 3.0. You have to check the environment variable MSBuildSDKsPath after every install of a new SDK. It must target the SDK you use to create your project. I use VS2017 with Windows 10.

For 2.2 SDK:

C:\Program Files\dotnet\sdk\2.2.104\Sdks

For 3.0 preview :

C:\Program Files\dotnet\sdk\3.0.100-preview3-010431\Sdks 
Tim
  • 5,435
  • 7
  • 42
  • 62
MNF
  • 687
  • 9
  • 13
0

I resolve the issue by installing the package directly form the Package Manager Console:

Install-Package NETStandard.Library -Version 2.0.3

0

Had the same issue after I updated (snip) all VS installations on my windows machine a while ago. A restart of my PC resolved the issue.

Namujiji
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 16 '22 at 19:08
0

I had this same issue, and it turned out the resolution for me was none of the above for me. I was running the VS preview version with an older version of VS. I removed the Preview VS and then had to remove each of the environment variables by hand (i.e ANDRIOD_HOME, and .Net Maui vars, etc) and was back in business. Hope this helps someone out there who has installed VS Preview only to break the dev build environment.

0

Cause I had a lot of diffeculties finding the url for build tools, here it is :

https://aka.ms/vs/16/release/vs_buildtools.exe

Documenantion : https://learn.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual-studio?view=vs-2019

FrqSalah
  • 472
  • 3
  • 9
0

I encountered the same error and to fix it I installed .NET 6.0 SDK. https://dotnet.microsoft.com/en-us/download/visual-studio-sdks

SDK Download Website Link

I only had .NET 7.0 SDK installed, and for whatever reason the project I was trying to use needed .NET 6.0 SDK.

nicko
  • 460
  • 3
  • 11
0

I ran into this issue after installing .NET 7 to work with gRPC. After uninstalling .NET 7 the IDE was still looking for it. I deleted the empty C:\Program Files\dotnet\sdk\7 folder. I closed an opened the project it found the lastest .NET 6 installation.

Elim Garak
  • 1,728
  • 1
  • 16
  • 21
0

I tried almost all in this thread without success. I was able to fix the issue by changing the PATH environment variable. I had "C:\Program Files (x86)\dotnet" and after "C:\Program Files\dotnet". The solution was to put "C:\Program Files (x86)\dotnet" after "C:\Program Files\dotnet". Solved!

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 08 '23 at 15:36
0

I installed a different version of Visual Studio and then my projects were able to load.

Previously, I installed 17.6, which did not work for my projects. Then I installed 17.4 and that worked.

enter image description here

Thuy
  • 1,493
  • 1
  • 11
  • 11
0

If you have different versions of Sdks installed in your system, then updating environment variable must be using and old Out-Of-Support version of Sdk.

Under "User variable" section look for "MSBuildSDKsPath" and update the latest version Sdk path

enter image description here

ntn
  • 330
  • 2
  • 3
  • 10