Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

.NET6 - MSB4236: The SDK ‘Microsoft.NET.Sdk’ specified could not be found

Describe the bug

After installing .NET6 on Windows Server 2016 every project that I try to build on that machine fails due to MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found

To Reproduce

Install latest SDK (.NET6) and Runtime on Windows Server 2016. Doesn’t matter if I use .NET installer or binaries or even Visual Studio Build Tools 2022

Exceptions (if any)

On my local dev machine - Windows 10, everything works fine

Further technical details

This machine used to have all the previous .NET Core SDKs and Runtimes. I have uninstalled all of them so my machine is clean. I have also checked Environment Variables and they also look normal.

Windows Server 2016 dotnet --info

.NET SDK (reflecting any global.json):
 Version:   6.0.101
 Commit:    ef49f6213a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.101\

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  6.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

VaslDcommented, Jun 21, 2022

I think I’ve found the cause of this problem.

My system environment variables contain an entry for MSBuildSDKsPath, which points to C:\Program Files\dotnet\sdk. It looks harmless.

In C:\Program Files\dotnet\sdk\6.0.301\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution.targets, the target definition/template references $(MSBuildSDKsPath)\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets, which resolves to C:\Program Files\dotnet\sdk\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets given MSBuildSDKsPath but there’s nothing there.

Deleting that MSBuildSDKsPath from environment variables (and restarting affected terminals and IDEs to apply the change) fixed it for me.

PS: I found out about this because when I did a dotnet restore and the error log became:

C:\Program Files\dotnet\sdk\6.0.301\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution.targets(14,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" is correct, and that the file exists on disk.

Which explained what was happening much better, and pointed so much closer to the real issue in contrast to “SDK not found”. “Not found” is like the second hardest problem to solve than “A problem occurred”. Please fix this, if not the issue, the message.

drewrodriguescommented, Oct 31, 2022

Add the environment variable MSBuildSDKsPath with the value of C:\Program Files\dotnet\sdk\6.0.402\Sdks\ (or whatever your sdk version is). Should do the trick!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The SDK 'Microsoft.NET.Sdk' specified could not be found. ...
The SDK 'Microsoft.NET.Sdk' specified could not be found. in Visual Studio Community 2022 version 17.5 · Right-click your project > Unload ...
Read more >
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 ......
Read more >
MSB4236 The SDK Microsoft.NET.Sdk specified could not ...
The error was error MSB4236 The SDK Microsoft.NET.Sdk specified could not be found and is because the project now includes dotnetcore ...
Read more >
Unable to locate the .NET SDK: The Reasons - Hamid Mosalla
Navigate to C:\Program Files\dotnet\sdk and see if you can find folders associated with different sdk versions. If you can't find any folder ...
Read more >
Error under Debug "The SDK 'Microsoft.NET.sdk' specified ...
I have now downloaded msbuild tools and routed the correct path and tried again and the "'msbuild' not found" error seems to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found