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

C#.NetMsbuild.Net Core

C# Problem Overview


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)

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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

Solution 3 - C#

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

Solution 4 - C#

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

Solution 5 - C#

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

Solution 6 - C#

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.

Solution 7 - C#

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.

Solution 8 - C#

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

Solution 9 - C#

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

Solution 10 - C#

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 

Solution 11 - C#

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.

Solution 12 - C#

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

Install-Package NETStandard.Library -Version 2.0.3

Solution 13 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLuiz Gustavo MaiaView Question on Stackoverflow
Solution 1 - C#Sebastian NemethView Answer on Stackoverflow
Solution 2 - C#YaselView Answer on Stackoverflow
Solution 3 - C#pawellipowczanView Answer on Stackoverflow
Solution 4 - C#HyperQuantumView Answer on Stackoverflow
Solution 5 - C#Nelcon CroosView Answer on Stackoverflow
Solution 6 - C#Vadzim PapkoView Answer on Stackoverflow
Solution 7 - C#hexView Answer on Stackoverflow
Solution 8 - C#rufus1530View Answer on Stackoverflow
Solution 9 - C#MarfyyView Answer on Stackoverflow
Solution 10 - C#MNFView Answer on Stackoverflow
Solution 11 - C#codewingView Answer on Stackoverflow
Solution 12 - C#yannick triqueneauxView Answer on Stackoverflow
Solution 13 - C#tanukView Answer on Stackoverflow