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

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

Closed
lgmguto opened this Issue Sep 16, 2017 · 44 comments

Comments

Projects
None yet
@lgmguto
Copy link

lgmguto commented Sep 16, 2017

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

@fanicia

This comment has been minimized.

Copy link

fanicia commented Oct 11, 2017

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

@DNF-SaS

This comment has been minimized.

Copy link

DNF-SaS commented Oct 13, 2017

Same here on Win7

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Nov 9, 2017

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?

@mayconpires

This comment has been minimized.

Copy link

mayconpires commented Nov 10, 2017

@fanicia thank you!!!

@DustinCampbell

This comment has been minimized.

Copy link
Member

DustinCampbell commented Nov 10, 2017

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

@fanicia

This comment has been minimized.

Copy link

fanicia commented Nov 10, 2017

@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

@greenmooseSE

This comment has been minimized.

Copy link

greenmooseSE commented Nov 10, 2017

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

@fanicia

This comment has been minimized.

Copy link

fanicia commented Nov 10, 2017

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

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

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

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

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?

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

Make sure to install the .NET Core workload:

image

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

Workload selection applies to full VS as well:

image

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

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.

@fanicia

This comment has been minimized.

Copy link

fanicia commented Nov 10, 2017

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

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

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

... are installed?

@fanicia

This comment has been minimized.

Copy link

fanicia commented Nov 10, 2017

^yes

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Nov 10, 2017

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

@fanicia

This comment has been minimized.

Copy link

fanicia commented Nov 10, 2017

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

@greenmooseSE

This comment has been minimized.

Copy link

greenmooseSE commented Nov 13, 2017

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

@paul1956

This comment has been minimized.

Copy link

paul1956 commented Nov 29, 2017

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

This comment has been minimized.

Copy link

venkateswaris commented Jan 15, 2018

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?

@rainersigwald

This comment has been minimized.

Copy link
Contributor

rainersigwald commented Jan 16, 2018

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

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Feb 12, 2018

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

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Feb 12, 2018

  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 ?

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Feb 12, 2018

@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

This comment has been minimized.

Copy link
Member

nguerrera commented Feb 12, 2018

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

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Feb 12, 2018

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

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Feb 12, 2018

Try this on Visual Studio command prompt:

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

Share resolver.log

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Feb 12, 2018

@nguerrera the resolver file is attached.

resolver.log

@vcaraulean

This comment has been minimized.

Copy link

vcaraulean commented Feb 20, 2018

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

@brunis

This comment has been minimized.

Copy link

brunis commented Apr 3, 2018

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

@pjmagee

This comment has been minimized.

Copy link

pjmagee commented Apr 13, 2018

The only solution that worked for this was this comment: dotnet/docfx#1752 (comment)

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");
@Amit-Kumar-Sonkar

This comment has been minimized.

Copy link

Amit-Kumar-Sonkar commented Jul 6, 2018

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

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Jul 9, 2018

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.

@RSuter

This comment has been minimized.

Copy link

RSuter commented Aug 31, 2018

@brunis

This comment has been minimized.

Copy link

brunis commented Oct 17, 2018

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\

@dark2201

This comment has been minimized.

Copy link

dark2201 commented Nov 9, 2018

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" />
@rainersigwald

This comment has been minimized.

Copy link
Contributor

rainersigwald commented Nov 19, 2018

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

@rainersigwald

This comment has been minimized.

Copy link
Contributor

rainersigwald commented Nov 19, 2018

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.

@dark2201

This comment has been minimized.

Copy link

dark2201 commented Nov 20, 2018

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

@rainersigwald

This comment has been minimized.

Copy link
Contributor

rainersigwald commented Nov 20, 2018

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

@Garwin4j

This comment has been minimized.

Copy link

Garwin4j commented Jan 31, 2019

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?

@bigswede74

This comment has been minimized.

Copy link

bigswede74 commented Feb 8, 2019

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.

@nguerrera

This comment has been minimized.

Copy link
Member

nguerrera commented Feb 8, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.