dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

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

Closed lgmguto closed 5 years ago

lgmguto commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Same here on Win7

DustinCampbell commented 7 years ago

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 commented 7 years ago

@fanicia thank you!!!

DustinCampbell commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Make sure to install the .NET Core workload:

image

nguerrera commented 7 years ago

Workload selection applies to full VS as well:

image

nguerrera commented 7 years ago

If you have Build tools SKU:

If you have full VS:

fanicia commented 7 years ago

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

nguerrera commented 7 years ago

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

... are installed?

fanicia commented 7 years ago

^yes

nguerrera commented 7 years ago

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

fanicia commented 7 years ago

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 commented 7 years ago

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

paul1956 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago
  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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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

nguerrera commented 6 years ago

Try this on Visual Studio command prompt:

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

Share resolver.log

bigswede74 commented 6 years ago

@nguerrera the resolver file is attached.

resolver.log

vcaraulean commented 6 years ago

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

What helped:

Without restarting the agent it will still fail...

brunis commented 6 years ago

@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 commented 6 years ago

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");
Amit-Kumar-Sonkar commented 6 years ago

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 commented 6 years ago

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.

RicoSuter commented 6 years ago

If this is still an issue, this may help: https://blog.rsuter.com/missing-sdk-when-using-the-microsoft-build-package-in-net-core/

brunis commented 6 years ago

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\

bugproof commented 6 years ago

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 commented 5 years ago

@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 commented 5 years ago

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.

bugproof commented 5 years ago

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

rainersigwald commented 5 years ago

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

Garwin4j commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

bugproof commented 5 years ago

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

rainersigwald commented 5 years ago

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

mickaelistria commented 5 years ago

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.

cyberkito commented 5 years ago

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.

uciprian commented 5 years ago

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

rainersigwald commented 5 years ago

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