Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) 
like image 637
Luiz Gustavo Maia Avatar asked Sep 16 '17 18:09

Luiz Gustavo Maia


People also ask

How do I get MSBuild without Visual Studio?

To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2022 on the downloads page. Another way of getting MSBuild is to install the . NET SDK.

How do I use MSBuild EXE?

Use MSBuild at a command prompt To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

What is Microsoft NET SDK Web?

NET. Sdk. Web is an MSBuild project SDK for building ASP.NET Core apps. It's possible to build an ASP.NET Core app without this SDK, however, the Web SDK is: Tailored towards providing a first-class experience.

Where is the global json file located?

The global. json file in the root of your project (or even in the root of your file system as the SDK will traverse the file system until it finds one) allows defining which version of the SDK to use.


1 Answers

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.

like image 161
Sebastian Nemeth Avatar answered Sep 22 '22 06:09

Sebastian Nemeth