Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tomabu opened this issue Jan 7, 2022 · 13 comments
Open

Comments

@tomabu
Copy link

tomabu commented Jan 7, 2022


.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:
  https://aka.ms/dotnet-download
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Install untriaged Request triage from a team member labels Jan 7, 2022
@StrajnarFilip
Copy link

I'm having the same error, MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found
The issue is only present on .NET 6 SDK, .NET 5 and 3.1 are working fine.

@dsplaisted
Copy link
Member

Does this happen when you run dotnet build, or msbuild, or both?

@dsplaisted dsplaisted added this to the Discussion milestone Mar 9, 2022
@dsplaisted dsplaisted removed the untriaged Request triage from a team member label Mar 9, 2022
@dsplaisted dsplaisted removed their assignment Mar 9, 2022
@ebmarquez
Copy link

Same issue for myself

msbuild Version

>msbuild -version
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

17.2.1.25201

dotnet build

>dotnet build
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
  * You intended to execute a .NET program:
      The application 'build' does not exist.
  * You intended to execute a .NET SDK command:
      A compatible installed .NET SDK for global.json version [6.0.300] from [C:\OnRamp\global.json] was not found.
      Install the [6.0.300] .NET SDK or update [C:\OnRamp\global.json] with an installed .NET SDK:
        5.0.408 [C:\Program Files\dotnet\sdk]
        6.0.105 [C:\Program Files\dotnet\sdk]

Build Tools

> Get-VSSetupInstance   

InstanceId          : 8c96e9e2
DisplayName         : Visual Studio Build Tools 2022
InstallationVersion : 17.2.32516.85
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
InstallDate         : 5/17/2022 10:22:51 AM

Dotnet --info

k>dotnet --info

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

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

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

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

@nh43de
Copy link

nh43de commented Jun 8, 2022

Also having this issue in Azure CI

@VaslD
Copy link

VaslD commented 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.

@primesun
Copy link

Adding my experience: I wasn't getting the MSB4236 error. Instead I was getting error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0. after running something like dotnet build or dotnet publish, or even dotnet restore. Notably I was only getting this error in the command line, not in Visual Studio, which found the right SDK without issue.

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

This worked for me too. Mine actually had this value in it before I deleted it: C:\Program Files\dotnet\sdk\5.0.300\Sdks.

I also confirmed that updating the MSBuildSDKsPath to the newer folder (C:\Program Files\dotnet\sdk\6.0.302\Sdks) also works. But since deleting the env var entirely works, there was no point to keep it.

Now I wonder why I even had it in the first place. I wonder if it was something related to vscode...

@pantonis
Copy link

I dont see MSBuildSDKsPath in my environment variables. Is this issue gonna be fixed??

@drewrodrigues
Copy link

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!

@ymeric
Copy link

ymeric commented Dec 28, 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!

This solution fixed my issues with VS 2019 and 2022. After I installed the latest versions of both IDEs they went MIA. 2019 could not load projects, and 2022 could not run them!!! First installed the latest NET 6 SDK which did not resolve the issue. Then applied this solution and voila!!! Thanks Drew.

@YouJiYun
Copy link

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.

It works for me.

@lqlam
Copy link

lqlam commented Jul 30, 2023

Does this happen when you run dotnet build, or msbuild, or both?

Thank. When I run command "dotnet build" it show error. I have to download Net 7 (x86 and x64) and worked

@alpugi
Copy link

alpugi commented Mar 15, 2024

Thanks guys, you put me on the right path: I had no environment variable for the sdk path and adding it only led to a more specific error (sub sdk missing). I had to change the Path environment variable (I'm on win 10):

move the "C:\Program Files\dotnet" entry on top of "C:\Program Files(x86)\dotnet"

solved the problem. For me it happened after a Visual Studio update. I did update build tools as well.

@eXpl0it3r
Copy link

For me the issue was with Microsoft.Build / Microsoft.Build.Utilites.Core usage in a test project.

I was still using Microsoft.Build 16.x and it seems to clash with dotnet test if your .NET SDK is 6 or 8, which kind of makes sense, when you consider that VS 2019 (V16) doesn't support .NET 6 and newer.

Updating to Microsoft.Build to 17.x fixed the error.

Additional tip: While I'm still running the tests in a NetFx 4.8 test host, I for some reason had to use Microsoft.Build 17.8.3, otherwise I'd run into conflict with System.Collections.Immutable, which was requested for V7.0.0, but Microsoft.Build > 17.8.3 uses V8.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests