Msbuild: error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

Created on 16 Sep 2017  路  56Comments  路  Source: dotnet/msbuild

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

Most helpful comment

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

All 56 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

Same here on Win7

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?

@fanicia thank you!!!

@mayconpires : Any chance you could try setting COREHOST_TRACE=1 per my comment above to give us some data about why this is happening?

@DustinCampbell i just tried unchecking the variable on one of our CI servers.... and now it works without it ???

I have changed a bunch of stuff on there since i wrote the comment though, so idk :P

I still have the issue for v15.4.8.50001 but setting COREHOST_TRACE=1 does not make any difference in the console output for msbuild.exe.

*Edit:
Initially dotnet build solution.sln resulted in same error in output (but still reported 'Build succeeded'). When trying with above COREHOST_TRACE, dotnet build spit out tons of log output I could not redirect to a file and now, for whatever reason, dotnet build solution.sln works fine. Invoking msbuild.exe directly still causes the same error (on server2, on server1 it works fine for same solution).

(I also get error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found, furthermore we had sdk junction paths in for C:\Program Files (x86)\Microsoft Visual Studio\2017\MsBuild\15.0\Sdks and ...\MsBuild\Sdks which both had target to C:\Program Files\dotnet\sdk\1.0.1\Sdks (1.0.1 had been uninstalled), I removed the 2 junction folders and repaired vs2017 build tools, reinstalled netCore 2.0.2 and rebooted. Still same issue.)

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

I still have the issue for v15.4.8.50001 but setting COREHOST_TRACE=1 does not make any difference in the console output for msbuild.exe.

This suggests to me that your msbuild.exe copy does not have the following:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver

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?

Make sure to install the .NET Core workload:

image

Workload selection applies to full VS as well:

image

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.

@nguerrera I am using the buildtools, not the full VS. Meaning the .Net Core cross-platform development you have highligted

Meaning the .Net Core cross-platform development you have highligted

... are installed?

^yes

You said it started working after changes to build machine. Is it possible the workload installation s one of those changes?

i dont think so. i was having trouble adding a required nuget package to the solution... will be able to give more info when im in office next week

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

I am using VS 2017 15.4.5 and unless I SetEnvironmentVariable's I get errors in a Test Project and the documents don't load. If I set it I still get errors loading the projects but they do load. When I build with Visual Studio I get no errors.

        Const SolutionPartialPath As String = "roslyn-master\src\Samples\Samples.sln"
        Const BasicCodeAnalysisPartialPath As String = "Roslyn-master\src\Compilers\VisualBasic\Portable"
        <TestMethod()> Public Sub ElementTypeUnitTestAsync()
            Dim registryKey As String
            If Environment.Is64BitProcess Then
                registryKey = "SOFTWARE\Microsoft\VisualStudio\SxS\VS7"
            Else
                registryKey = "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7"
            End If
            Using subKey As RegistryKey = Registry.LocalMachine.OpenSubKey(registryKey)
                Dim visualStudioPath As String = TryCast(subKey.GetValue("15.0"), String)
                If Not String.IsNullOrEmpty(visualStudioPath) Then
                    Environment.SetEnvironmentVariable("VSINSTALLDIR", visualStudioPath)
                    Environment.SetEnvironmentVariable("VisualStudioVersion", "15.0")
                    Environment.SetEnvironmentVariable("MSBuildSDKsPath", "C:\Program Files\dotnet\sdk\2.0.3\Sdks")
                End If
            End Using

            Dim myDoc As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
            Dim SampleSolutionPath As String = Path.Combine(myDoc, SolutionPartialPath)

            Dim MS_Workspace As MSBuildWorkspace = MSBuildWorkspace.Create()
            AddHandler MS_Workspace.WorkspaceFailed, Sub(sender As Object, e As WorkspaceDiagnosticEventArgs)
                                                         Debug.WriteLine(e.Diagnostic.ToString())
                                                     End Sub
            Dim NewSolution As Solution = MS_Workspace.OpenSolutionAsync(SampleSolutionPath).Result

            For Each Project In NewSolution.Projects
                Debug.WriteLine($"Project = {Project.Name}")
                If Project.Name = "BasicCodeAnalysis" Then
                    WalkProject(Project)
                    Exit For
                End If
            Next
        End Sub

Some of the errors

C:\Users\PaulM\.nuget\packages\microsoft.net.compilers\2.3.1\tools\Microsoft.VisualBasic.Core.targets: (73, 5): The "Vbc" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
[Failure] Msbuild failed when processing the file '...roslyn-master\src\Samples\UnitTestProject1\UnitTestProject1.vbproj' with message: The imported project "...VSIXProject2\CodeRefactoring1.Test\bin\Debug\Roslyn\Microsoft.VisualBasic.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  ...VSIXProject2\CodeRefactoring1.Test\bin\Debug\Microsoft.VisualBasic.CurrentVersion.targets

Hi @nguerrera

I have visual studio Build tools installed. I am trying to install .NET Core workload using choco. But that is failing. Is there any official page where i can download .NET Core workload?

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

I'm still getting this error with all three if the fixes mentioned above. All the build tools packages are the latest and visual studio is updated to the latest version as well.

  1. Path Variable MSBuildSDKsPath
  2. Build Tools for Visual Studio 2017
  3. Full Visual Studio 2017 installed with .NET Core Build Tools

[13:47:48][Step 4/9] Executing task: BuildSource
[13:47:49][Step 4/9] Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
[13:47:49][Step 4/9] Copyright (C) Microsoft Corporation. All rights reserved.
[13:47:49][Step 4/9]
[13:47:49][Step 4/9] C:\BuildAgent\work\MyProj.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
[13:47:49][Step 4/9] An error occurred when executing task 'BuildSource'.
[13:47:49][Step 4/9] Error: One or more errors occurred.
[13:47:49][Step 4/9] .NET Core CLI: Process returned an error (exit code 1).
[13:47:49][Step 4/9] Process exited with code 1

  1. Path Variable MSBuildSDKsPath

@bigswede74 What is PATH and what is MSBuildSdksPath?

Do you have C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver ?

@nguerrera I have added the PATH MSBuildSdksPath=C:\Program Files\dotnet\sdk\2.1.4\Sdks.

I do have the SdkResolver on the file system at the location above.

@nguerrera I have added the PATH MSBuildSdksPath=C:\Program Files\dotnet\sdk\2.1.4\Sdks.

You should not need MSBuildSdksPath to be set at all.

Is C:\Program Files\dotnet\ in your PATH environment variable?

@nguerrera yes I have the path variable C:\Program Files\dotnet.

Try this on Visual Studio command prompt:

set COREHOST_TRACE=1
msbuild C:\BuildAgent\work\MyProj.csproj 2> resolver.log

Share resolver.log

@nguerrera the resolver file is attached.

resolver.log

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

@nguerrera I'd prefer not to have to install .NET Core + SDK's + Runtimes just to build a .NET 4.6 class library.

edit: I see from @vcaraulean's post that it's just the .net core build tools, but still. Please try and untangle these unnessessary cross sdk/framework dependencies.

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.

c# // 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");

well nice job . nguerrera .. i tried it building sln from MSBuild.exe
accrodingly what u have said for installing must..

buildtools

indeed i checked it wasn't installed
after installed and launched it worked from Developer Command 2017...

build tools

Finally From MSBuild.exe
success build

I have updated the .NET Core Build Tools to v15.7.4 and still get the following error when trying to compile.

error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

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

How did you get that wrong path? they are in C:\Program Files\dotnet\sdk\

I tried building my .NET Core project programmatically using Microsoft.Build, I got this error, after setting appropriate environment variables I got stackoverflow exception and "new guard page for stack cannot be created"

I tried using BuildManager.DefaultBuildManager, Project and ProjectInstance.

EDIT:

Apparently the crash was caused because I needed to install more Nuget packages!

After adding these packages it works fine!:

 <PackageReference Include="Microsoft.Build" Version="15.8.166" />
    <PackageReference Include="Microsoft.Build.Framework" Version="15.8.166" />
    <PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.8.166" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.8.166" />

@Sigvaard you'll probably have an easier time if you use MSBuildLocator. See https://docs.microsoft.com/en-us/visualstudio/msbuild/updating-an-existing-application?view=vs-2017.

I'm going to close this since it encompasses multiple situations; if you run into a problem with this symptom, please file a new bug with repro steps.

@rainersigwald I'm targeting .NET Core, MSBuildLocator targets .NET Framework 4.6 and I can't use it in my project.

@Sigvaard You'll want to follow Microsoft/MSBuildLocator#30 and Microsoft/MSBuildLocator#51 then.

I got this error after installing SSDT as a separate instance. I notice that it seems to defaulting to this version (which doesn't have everything installed):

MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\MSBuild\15.0\bin'.

How would I switch back?

Why has this issue been closed, none of the fixes listed here have worked. I have tried all of them and yet I still see the error.

@bigswede74 for the reason @raines stated, the same error can occur in many different circumstances. Please open a new issue and describe your full setup and repro steps. Thank you.

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

@dark2201 Can you please open a new issue, describing the conditions you're in and the exact error? Please tag me when you do.

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.

I used my local installation

  1. Path Variable MSBuildSDKsPath

@bigswede74 What is PATH and what is MSBuildSdksPath?

Do you have C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver ?

I used my local VS 2017 installation and copied resolver to build server and problem was fixed.

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

@uciprian do you have the ".NET Core Build Tools" workload enabled for your build tools installation?

I stumbled into this problem today, building an app that use roslyn, here there is a repro repository with a Dockerfile based upon mcr.microsoft.com/dotnet/core/sdk:3.0.100-rc1-bionic image.

The program tries to analyze a simple console test source and generate warning at this line, following is the execution of the docker image that can be built and run using this script contained in the repository

Successfully tagged repros/netcore-roslyn-01:latest
------------ENTRYPOINT
3.0.100-rc1-014190 [/usr/share/dotnet/sdk]
dotnet executable = [/usr/bin/dotnet]
PATH              = [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
DOTNET_ROOT       = [/usr/share/dotnet]
MSBuildSDKsPath   = [/usr/share/dotnet/sdk/3.0.100-rc1-014190/Sdks]
---> OpenProject
Msbuild failed when processing the file '/src/test/test.csproj' with message: The imported project "/app/Current/Microsoft.Common.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  /usr/share/dotnet/sdk/3.0.100-rc1-014190/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
---> GetCompilation
has documents = False

UPDATE

fixed by adding MSBUILD_EXE_PATH ( see here )

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.

I did all kind of stuff, this is the only thing that worked form me

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.

This Works Like a charm . Thanks

add environment variables MSBuildSDKsPath with value "C:\Program Files\dotnet\sdk\2.0.0\Sdks" does not work for me.

copy SdkResolvers from local to build server works for me

For me it worked by running dotnet build instead of using msbuild

@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"
Was this page helpful?
0 / 5 - 0 ratings