msbuild: error MSB4236: 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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 43
  • Comments: 58 (19 by maintainers)

Commits related to this issue

Most upvoted comments

I fixed this by creating a path variable “MSBuildSDKsPath” with the value “C:\Program Files\dotnet\sdk\2.0.0\Sdks”

I don’t know why msbuild can’t find this path by default, but this fixed the issue for us

Make sure to install the .NET Core workload:

image

Anyone who’s still having trouble here, could you try unsetting MSBuildSDKsPath and see if the issue still repros. If it does, could you set COREHOST_TRACE=1, reproduce the issue, and then paste the trace output here?

If you have Build tools SKU:

  • You cannot get Microsoft.NET.Sdk or Microsoft.NET.Sdk.Web to resolve without the .NET Core workload installed.

If you have full VS:

  • You can get Microsoft.NET.Sdk to resolve without the .NET Core or ASP.NET workloads installed, but it will be locked to version 1.x instead of resolving the latest version or global.json implied version.

  • You cannot get Microsoft.NET.Sdk.Web to resolve without the .NET Core workload or ASP.NET workloads installed.

Is everyone reporting this using “Build Tools for Visual Studio 2017” https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017

rather than full VS?

I ran OmniSharp with COREHOST_TRACE=1 as suggested by @DustinCampbell and could see the following messsage

Searching SDK directory in [/usr/local/bin]
--- Resolving SDK version from SDK dir [/usr/local/bin/sdk]
Checking if resolved SDK dir [/usr/local/bin/sdk/-1.-1.-1] exists
It was not possible to find any SDK version

FWIW, on my machine, dotnet in installed in /usr/lib64/dotnet and has a link in /usr/bin. I looked inside the /usr/local/bin directory and found a dead symbolic link /opt/dotnet. I removed the symbolic link, and MSBuild now properly resolves the SDK.

The only solution that worked for this was this comment: https://github.com/dotnet/docfx/issues/1752#issuecomment-323385945

So basically I needed to add the config and change the MsBuild Path to the one inside the SDK, not use the MSBuild that’s part of Visual Studio 2015.

 // https://github.com/dotnet/docfx/issues/1752#issuecomment-323385945
Environment.SetEnvironmentVariable("MSBuildSDKsPath", "C:\\Program Files\\dotnet\\sdk\\2.1.104\\Sdks");
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", "C:\\Program Files\\dotnet\\sdk\\2.1.104\\MSBuild.dll");

Just a FYI, it might help somebody else. Our setup:

  • new csproj targeting net46
  • TeamCity
  • Build failing with error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found

What helped:

  • Instal .NET Core build tools, as suggested by @nguerrera
  • Restart TeamCity agent

Without restarting the agent it will still fail…

@fanicia thank you!!!

@venkateswaris

If you install via choco, you need to include workloads you would normally include via the GUI:

https://github.com/dotnet/msbuild/issues/2532#issuecomment-343578403

For me, I used this choco command:

choco install visualstudio2019buildtools --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"

@venkateswaris The official way to install the .NET Core workload is either through the Build Tools installer UI or its command line options. Documentation for the command line is here and a list of workloads for the Build Tools installer is here. In your case you probably want to ensure that the Microsoft.VisualStudio.Workload.NetCoreBuildTools workload is installed.

Workload selection applies to full VS as well:

image

Tried first MSBuildSdksPath no success Updated the build tools 2017 to latest version did not work also Copying my local VS 2017 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\SdkResolvers to build server solved for me the issue also!

Ideally an update for build tools for visual studio 2017 package should fix this

For some reason .NET Core 3 preview’s MSBuild.dll breaks it again and I have to set the path (MSBUILD_EXE_PATH) to 2.2. (I’m using @RSuter fix). I’m using MSBuild API to load the projects and it fails if MSBUILD_EXE_PATH is set to 3.0 MSBuild.dll

@nguerrera Thanks. That was indeed our problem on server2, it was missing the .net core workload. After including it, it works fine!

To clarify. I was also in the case where i was able to build with dotnet build, but msbuild /t:rebuild didn’t work