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 · 59 comments
Closed
Labels

Comments

@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
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
Copy link

DNF-SaS commented Oct 13, 2017

Same here on Win7

@DustinCampbell
Copy link
Member

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
Copy link

@fanicia thank you!!!

@DustinCampbell
Copy link
Member

@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
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
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
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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Make sure to install the .NET Core workload:

image

@nguerrera
Copy link
Contributor

nguerrera commented Nov 10, 2017

Workload selection applies to full VS as well:

image

@nguerrera
Copy link
Contributor

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
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
Copy link
Contributor

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

... are installed?

@fanicia
Copy link

fanicia commented Nov 10, 2017

^yes

@nguerrera
Copy link
Contributor

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

@fanicia
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
Copy link

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

@paul1956
Copy link

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
Copy link

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
Copy link
Member

@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
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
Copy link
Contributor

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
Copy link

@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
Copy link
Contributor

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

@rainersigwald
Copy link
Member

@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
Copy link

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
Copy link

cyberkito commented Aug 23, 2019

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
Copy link

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
Copy link
Member

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

devel0 added a commit to devel0/repros that referenced this issue Sep 17, 2019
@devel0
Copy link

devel0 commented Sep 17, 2019

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 )

@epgeroy
Copy link

epgeroy commented Oct 9, 2019

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

@saeedtabrizi
Copy link

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

@cwhsu1984
Copy link

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

@mkonars
Copy link

mkonars commented Mar 3, 2020

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

@atniomn
Copy link

atniomn commented Jul 22, 2020

@venkateswaris

If you install via choco, you need to include workloads you would normally include via the GUI:

#2532 (comment)

For me, I used this choco command:

choco install visualstudio2019buildtools --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"

@igitur
Copy link

igitur commented Mar 20, 2022

Anyone who's still having trouble here, could you try unsetting MSBuildSDKsPath and see if the issue still repros.

This solved it for me, because previously I had a mixture of standard dotnet SDK installs (via Visual Studio), but also via scoop package manager. I had since removed scoop's version, but the environment variable was still pointing to the scoop directory. Just deleting the MSBuildSDKsPath environment variable thus solved it for me.

It would have been nice if the tool output this:
error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found IN THIS FREEKING DIRECTORY: C:\asdf\asdf\asdf\

@adelriosantiago
Copy link

Before adding the MSBuildSDKsPath env variable you might first want to see if the dotnet.exe is working. You can navigate to where dotnet.exe is (in my case it was "C:\Program Files\dotnet") and then execute the command you want to run. I was able to run dotnet tool install -g csharpier correctly after this. Adding the env variable didn't help.

@AR-May AR-May added the triaged label Feb 21, 2024
@loop-evgeny
Copy link

In my case this error was caused by a nearly empty SDK directory under %ProgramFiles%\dotnet\sdk: dotnet/sdk#41022

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

No branches or pull requests