Error msb4236 the sdk microsoft net sdk specified could not be found

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

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


Closed

lgmguto opened this issue

Sep 16, 2017

· 58 comments

Comments

@lgmguto

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:ProjectsMyProject.sln

enghch, tevert, StephenCleary, akhosravian, rjmooney, Banders2, fanicia, venkateswaris, greenmooseSE, NLI-KelbyHunt, and 33 more reacted with thumbs up emoji

@fanicia

I fixed this by creating a path variable «MSBuildSDKsPath» with the value
«C:Program Filesdotnetsdk2.0.0Sdks»

I don’t know why msbuild can’t find this path by default, but this fixed the issue for us

Kadajski, DNF-SaS, murilobeltrame, Shockolate, pquiring, greenmooseSE, mayconpires, ole1986, neutmute, steve-swanson, and 133 more reacted with thumbs up emoji
brunis, TraGicCode, subski, CommanderTvis, Karabaev, and vijaykumartk reacted with thumbs down emoji
IgorZudov, webasoo, giavudangle, PMAlexandrovich, and MiniaczQ reacted with laugh emoji
steve-swanson, gandarez, GlebGolovushkin, pjmagee, unquietwiki, RamenTurismo, Tobiaqs, samw2703, clockworkmice, Hokutosei, and 12 more reacted with hooray emoji
cesczacks reacted with confused emoji
steve-swanson, gandarez, chrisdamba, GlebGolovushkin, adrianriepl, pjmagee, 3rdvision, kredenac, Tobiaqs, clockworkmice, and 19 more reacted with heart emoji
beaubgosse, Arzio, webasoo, JakubHolovsky, Levinson02, pizycki, pferreirafabricio, PMAlexandrovich, and MiniaczQ reacted with rocket emoji
nclettiere, omarpiani, thepirat000, PMAlexandrovich, and MiniaczQ reacted with eyes emoji

@DNF-SaS

@DustinCampbell

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?

nguerrera, NoelWidmer, Prechytoo, codyborn, mortzi, jjallen37, abbatepabloo, nate141, ewilansky, UweKeim, and 2 more reacted with thumbs up emoji
MiniaczQ and JonathanChan1234 reacted with laugh emoji
MiniaczQ reacted with hooray emoji
MiniaczQ reacted with heart emoji
MiniaczQ reacted with rocket emoji
MiniaczQ reacted with eyes emoji

@mayconpires

@DustinCampbell

@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

@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

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 Studio2017MsBuild15.0Sdks and ...MsBuildSdks which both had target to C:Program Filesdotnetsdk1.0.1Sdks (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

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

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 Studio2017EnterpriseMSBuild15.0BinSdkResolversMicrosoft.DotNet.MSBuildSdkResolver

@nguerrera

brunis, psmolkin, hardhub, tmeckel, dariogriffo, jcansdale, apriyadarsheeD2L, dmangiarelli, ssg, ricky-hartmann-zocdoc, and m-v-k reacted with thumbs up emoji

@nguerrera

Make sure to install the .NET Core workload:

image

neutmute, elementum, venkateswaris, TommyN, shieldsjared, heavenwing, lennartb-, scarymrgrey, arnileibovits, DmytryEmery, and 30 more reacted with thumbs up emoji
wgv-srbrills, aminipour, toomastahves, and jbparker reacted with hooray emoji
ryancdotnet, akki, jbparker, and nacitar reacted with heart emoji

@nguerrera

Workload selection applies to full VS as well:

image

@nguerrera

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.

christianrondeau, triforcely, lennartb-, hardhub, petey284, ChrisMaddock, steverukuts, Jaimera, valmaev, gabrielweyer, and luferogo reacted with thumbs up emoji

@fanicia

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

@nguerrera

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

… are installed?

@fanicia

@nguerrera

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

@fanicia

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

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

@paul1956

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-mastersrcSamplesSamples.sln"
        Const BasicCodeAnalysisPartialPath As String = "Roslyn-mastersrcCompilersVisualBasicPortable"
        <TestMethod()> Public Sub ElementTypeUnitTestAsync()
            Dim registryKey As String
            If Environment.Is64BitProcess Then
                registryKey = "SOFTWAREMicrosoftVisualStudioSxSVS7"
            Else
                registryKey = "SOFTWAREWow6432NodeMicrosoftVisualStudioSxSVS7"
            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 Filesdotnetsdk2.0.3Sdks")
                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:UsersPaulM.nugetpackagesmicrosoft.net.compilers2.3.1toolsMicrosoft.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-mastersrcSamplesUnitTestProject1UnitTestProject1.vbproj' with message: The imported project "...VSIXProject2CodeRefactoring1.TestbinDebugRoslynMicrosoft.VisualBasic.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  ...VSIXProject2CodeRefactoring1.TestbinDebugMicrosoft.VisualBasic.CurrentVersion.targets

@venkateswaris

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

@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

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

  1. Path Variable MSBuildSDKsPath

@bigswede74 What is PATH and what is MSBuildSdksPath?

Do you have C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0BinSdkResolversMicrosoft.DotNet.MSBuildSdkResolver ?

@bigswede74

@nguerrera I have added the PATH MSBuildSdksPath=C:Program Filesdotnetsdk2.1.4Sdks.

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

@nguerrera

@nguerrera I have added the PATH MSBuildSdksPath=C:Program Filesdotnetsdk2.1.4Sdks.

You should not need MSBuildSdksPath to be set at all.

Is C:Program Filesdotnet in your PATH environment variable?

@bugproof

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

@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

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

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 Studio2017EnterpriseMSBuild15.0BinSdkResolversMicrosoft.DotNet.MSBuildSdkResolver ?

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

@uciprian

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 Studio2017CommunityMSBuild15.0BinSdkResolvers to build server solved for me the issue also!

Ideally an update for build tools for visual studio 2017 package should fix this

@rainersigwald

@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

@devel0

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

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

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

smaillet

added a commit
to smaillet/Llvm.NET
that referenced
this issue

Feb 20, 2020

@smaillet

@cwhsu1984

add environment variables MSBuildSDKsPath with value «C:Program Filesdotnetsdk2.0.0Sdks» does not work for me.

copy SdkResolvers from local to build server works for me

@mkonars

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

@atniomn

@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

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:asdfasdfasdf

@adelriosantiago

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

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:ProjectsMyProject.sln

Complete log:

    Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
    Build started 9/16/2017 3:09:03 PM.
    Project "C:ProjectsMyProject.sln" on node 1 (restore target(s)).
    ValidateSolutionConfiguration:
      Building solution configuration "Release|Any CPU".
    Project "C:ProjectsMyProject.sln" (1) is building "C:ProjectsKernelKernel.csproj" (2) on node 1 (restore target(s)).
    C:ProjectsMyProject.sln" (1) is building "C:ProjectsKernelKernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
    Done Building Project "C:ProjectsMyProject.sln" (1) is building "C:ProjectsKernelKernel.csproj" (restore target(s)) -- FAILED.

    Build FAILED.
    "C:ProjectsMyProject.sln" (restore target) (1) ->
"C:ProjectsKernelKernel.csproj" (restore target) (2) ->
  C:ProjectsKernelKernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

0 Warning(s)
    11 Error(s)

asked Sep 16, 2017 at 18:54

Luiz Gustavo Maia's user avatar

6

I encountered this error after playing around with .Net Core 2.0 installation and seemingly messing it up. I would get this same error for dotnet restore, dotnet build or dotnet msbuild. Essentially, anything involving .Net Core and msbuild.

The error occurred because the MSBuildSDKsPath environment variable was still pointing to the old .Net Core 1.1 SDK.

To fix the problem, I manually set the MSBuildSDKsPath environment variable to point to 2.0.0’s SDK path, which, for me with x64, this was at: C:Program Filesdotnetsdk2.0.0Sdks.

Basically, if you have Sdk="Microsoft.NET.Sdk" in your .csproj, then a folder with the same name should exist at your MSBuildSDKsPath location.

answered Sep 21, 2017 at 8:32

Sebastian Nemeth's user avatar

Sebastian NemethSebastian Nemeth

5,2114 gold badges25 silver badges36 bronze badges

6

You were probably missing some components when you installed the VS tools

  1. Download and run Build Tools for Visual Studio 2019. (On the VS download page, go to Tools for Visual Studio 2019 and then click download Build Tools for Visual Studio 2019)

  2. Select Modify on Visual Studio Build Tools 2019 or your instance.
    enter image description here

  3. Select tab Individual components and check .NET Core SDK component
    enter image description here

answered Nov 4, 2020 at 12:07

Yasel's user avatar

YaselYasel

2,8504 gold badges42 silver badges48 bronze badges

5

for me the solution was to set the sdk version in the global.json file:
solution items global.json

and specify the correct version which exists in the C:Program Filesdotnetsdk folder. The VS installer uninstalled the previous version of .NET Core 3.0.100 and installed new one 3.1.100 so I had to change it from:

{  "sdk": {    "version": "3.0.100"  }}

to

{  "sdk": {    "version": "3.1.100"  }}

answered Dec 5, 2019 at 10:44

pawellipowczan's user avatar

2

For me updating Visual Studio Build Tools resulted in the ‘SDK not found’ error.

The solution: run Visual Studio Installer, modify the Visual Studio (Build Tools) installation, and make sure the following workload is selected:

check ".NET build tools"

answered Sep 9, 2021 at 10:49

HyperQuantum's user avatar

HyperQuantumHyperQuantum

1,4421 gold badge10 silver badges12 bronze badges

1

I got this issue in Mac OS and while using docker container and Azure this occurs because docker bash overrides MSBuildSDKsPath so don’t
change any code just quit and restart your IDE (visual studio Mac) and run it again

answered May 25, 2020 at 16:03

Nelcon Croos's user avatar

2

I got the same issue when I tried to install x64 .Net Core SDK installer. Even the following dotnet --info command shows me that no SDK is found.

So, try to install x86 .Net Core SDK installer. That can help you.

Tim's user avatar

Tim

5,2466 gold badges44 silver badges60 bronze badges

answered Mar 25, 2019 at 8:53

Vadzim Papko's user avatar

I had the same problem and found solution here:
https://github.com/aspnet/AspNetCore/issues/3624

Solution is to just have x64 or x86 version of sdk/runtime/hosting.
If you have both and if you use for example x86 version of dotnet.exe it won’t see x64 versions of SDK installed.

Problem usually occures when you install hosting bundle because it includes both x86 and x64. Just uninstall one you don’t use.

answered Sep 27, 2019 at 11:48

hex's user avatar

hexhex

6931 gold badge11 silver badges17 bronze badges

To anyone that, like me, run into this issue on Linux and found this thread:

This problem occurs, because your .bashrc config overrides MSBuildSDKsPath environment variable with outdated value (most likely it’s a leftover after dotnet package update). To solve this:

  1. Edit ~/.bashrc
  2. Remove the line with MSBuildSDKsPath variable initialization, e.g.

export MSBuildSDKsPath=»/opt/dotnet/sdk/2.2.108/Sdks/»

answered Feb 6, 2020 at 12:54

rufus1530's user avatar

rufus1530rufus1530

7654 silver badges18 bronze badges

If you have previously worked with C# and it somehow stopped working:


For me updating to the latest version (probably of the build tools) with the «Visual Studio Installer» solved the problem.

answered Dec 24, 2020 at 9:50

codewing's user avatar

codewingcodewing

6648 silver badges24 bronze badges

1

I started getting this error after installing Visual Studio 2022 in Windows 10, when I opened up my solution. The solution contains a mix of .NET Framework 4.8 and .NET Standard 2.0 projects, and the error was on the .NET Standard 2.0 projects. I had previously Visual Studio 2019 and 2019 Build Tools installed.

The problem was that I had both x86 and x64 of dotnet installed, and both was in my systems PATH environment variable:

C:Program Files (x86)dotnet
C:Program Filesdotnet

I did the following steps to fix this error:

  • Uninstalled VS2019
  • Uninstalled VS2019 Build Tools
  • Removed the x86 path from the environment variable
  • Removed the folder «C:Program Files (x86)dotnet» from my computer
  • Restarted VS2022

I think that the important part was to remove x86 from the environment variable. The other steps was just to «clean up».

answered Nov 10, 2021 at 8:49

Marfyy's user avatar

I resolve the issue by installing the package directly form the Package Manager Console:

Install-Package NETStandard.Library -Version 2.0.3

answered Jun 18, 2021 at 14:18

yannick triqueneaux's user avatar

Maybe you encountered the error after installing .NET core SDK 3.0. You have to check the environment variable MSBuildSDKsPath after every install of a new SDK. It must target the SDK you use to create your project. I use VS2017 with Windows 10.

For 2.2 SDK:

C:Program Filesdotnetsdk2.2.104Sdks

For 3.0 preview :

C:Program Filesdotnetsdk3.0.100-preview3-010431Sdks 

Tim's user avatar

Tim

5,2466 gold badges44 silver badges60 bronze badges

answered Mar 10, 2019 at 20:33

MNF's user avatar

MNFMNF

6799 silver badges13 bronze badges

The issue was occuring for me only when I tried to build the project with
dotnet build using VS2022 .
MsBuild on the same project was working fine.

What I did was:

  • restore the .net core runtime sdk — I was using 3.1 at the time. enter image description here

  • Add both sdk paths in both Path vars, for the user and system, in that order:
    enter image description here

  • Delete the MSBuildSDKsPath

P.s. I had this error while trying to run the coverlet coverage analysis

answered Apr 28, 2022 at 8:04

tanuk's user avatar

tanuktanuk

46810 silver badges9 bronze badges

Had the same issue after I updated (snip) all VS installations on my windows machine a while ago. A restart of my PC resolved the issue.

answered Jun 15, 2022 at 16:44

Namujiji's user avatar

1

I had this same issue, and it turned out the resolution for me was none of the above for me.
I was running the VS preview version with an older version of VS. I removed the Preview VS and then had to remove each of the environment variables by hand (i.e ANDRIOD_HOME, and .Net Maui vars, etc) and was back in business. Hope this helps someone out there who has installed VS Preview only to break the dev build environment.

answered Jul 15, 2022 at 21:30

dePhantom's user avatar

answered Sep 16, 2022 at 13:25

FrqSalah's user avatar

FrqSalahFrqSalah

4723 silver badges9 bronze badges

I ran into this issue after installing .NET 7 to work with gRPC. After uninstalling .NET 7 the IDE was still looking for it. I deleted the empty C:Program Filesdotnetsdk7 folder. I closed an opened the project it found the lastest .NET 6 installation.

answered Jan 10 at 15:03

Bortus's user avatar

BortusBortus

1,6981 gold badge15 silver badges21 bronze badges

11 Jan 2020

Background

Recently I was working on a website built before dotnetcore was even a thing. It was targeting an older version of the original .NET Framework.

I am slowly modernizing it. Firstly I upgraded the nuget packages and re-targeted it to .NET Framework version 4.8.

Next, as the solution was split into many projects I was able to migrate many of these projects to be netstandard.

The idea is that all that is left is to think about upgrading the website to a Razor Pages aspnetcore project from the classic model view controller website.

Missing SDK Build Error

While I was doing this a build script was failing.

2020-01-11-15.00.04.png

The error was error MSB4236 The SDK Microsoft.NET.Sdk specified could not be found and is because the project now includes dotnetcore projects that need building.

The solution

After some googling the answer was to upgrade the Microsoft Visual Studio 2019 Build Tools installed on that server.

2020-01-11-14.57.39.png

Select .NET Core Build Tools and/or Web development build tools and install

2020-01-11-14.59.06.png

Once this was done the build worked.

Success 🎉

When working with Azure DevOps, or locally sometimes with Visual Studio, you may get the following error if there’s a mismatch. It can depend on what versions of the SDK you’ve got on your machines, either local or build agent.

Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.

A related error message that I also see regularly together with the one above is:

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

This error can happen when the defined version of the .NET Core SDK differs from the configured value when running the dotnet tools. (e.g., the SDK version).
Realizing others may run into the same, here are some quick ways that I made it work — if it can help anyone, that’s great.

Option: Define the correct .NET Core SDK in Azure DevOps

If you’re using Azure DevOps, you can easily define the version of the .NET SDK that should be targeted when running the dotnet commands.

You already should know the version you want to target. In my example, it’s 2.2.402. Knowing this means you can ensure that your build pipeline points to the correct versions too.

Use the correct .NET Core SDK version using a Task in the UI.

If you use the visual designer for building your Azure DevOps pipelines, you can define the .NET Core SDK version to use super-easy.

Add a new build task named Use .NET Core:

Azure DevOps build Task that defines the .NET Core version to target.

In a simple pipeline, it can look like this. Ensure that the task you add is at the beginning, so all subsequent dotnet tasks use the version you’ve defined:

Use .NET Core build task in Azure DevOps

As a verification, I also added a custom .NET Core task dotnet --list-sdks which will output in the console log what version is being targeted. Sure enough, it ensures that the configuration was a success.

Use the correct .NET Core SDK version using YAML

If you’re using YAML pipelines instead of the visual pipelines, the task(s) look like this.

Specify the .NET Core version to target in the pipeline:

steps:
- task: UseDotNet@2
  displayName: 'Use .Net Core sdk 2.2.402'
  inputs:
    version: 2.2.402
    includePreviewVersions: true

Verify that the pipeline indeed is using the correct version when it runs:

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet --list-sdks '
  inputs:
    command: custom
    custom: '--list-sdks '

I resolved all the issues without any code changes, which is what I ideally want — no changes to code due to tooling or SDK issues.

Option: adjust global.json

Unless it’s about upgrading to the latest security patch or version, I wouldn’t consider changing the version in the codebase unless there is a logical reason. I’d instead do it in the pipelines and ensure the tools know how to work with the code.

If you want to go down the other route and modify the global.json, you can, of course, do that to match whatever version the build agents and developers have installed.

A global.json file can look like this:

{
  "sdk": {
    "version": "2.2.402"
  }
}

More reading

  • global.json overview (Microsoft Docs)
  • Using the .NET Core Task (Microsoft Docs)

This article describes why you get the error «The SDK ‘Microsoft.Net.Sdk.Web’ specified could not be found» when creating a new project in Visual Studio 2017 15.3, which prevents the project from loading, and how to fix it.

tl;dr; I had a rogue global.json sitting in a parent folder, that was tying the SDK version to 1.X. Removing that, (or adding a global.json for 2.x fixed the problem).

Update: Shortly after publishing this post, I noticed a tweet from Patrik who was getting a similar error, but for a different situation. He had installed the VS 2017 15.3 update, and could no longer open ASP.NET Core 1.1 projects!

Upgraded VS2017 and now I can’t open my netcore1.1 projects anymore. Great QA! :)

— Patrik (@firstdrafthell) 15 August 2017

It turns out, he’d uncovered the route of the problem, and the issue I was having — VS 2017 update 3 is incompatible with the 1.0.0 SDK:

Thanks! I managed to figure it out. Can’t use SDK 1.0.1 with VS 2017 15.3. Had to update build servers and bump to 1.0.4.

— Patrik (@firstdrafthell) 15 August 2017

Kudos to him for figuring it out!

2.0 all the things

As I’m sure anyone who’s reading this is aware, Microsoft released the final version of .NET Standard 2.0, .NET Core 2.0, and ASP.NET Core 2.0 yesterday. These brings a huge number of changes, perhaps most importantly being the massive increase in API surface brought by .NET STandard 2.0, which will make porting applications to .NET Core much easier.

As part of the release, Microsoft also released Visual Studio 2017 update 3. This also has a bunch of features, but most importantly in supports .NET Core 2.0. Before this point, if you wanted to play with the .NET Core 2.0 bits you had to install the preview version of Visual Studio.

That’s no longer as scary as it once was, with VS new lightweight installer and side by side installers. But I’ve been burned one to many times, and just didn’t feel like risking having to pave my machine, so I decided to hold off the preview version. That didn’t stop me playing with the preview bits of course, OmniSharp means developing in VS Code and with the CLI is almost as good, and JetBrains Rider went RTM a couple of weeks ago.

Still, I was excited to play with 2.0 on my home turf, in Visual Studio, so I:

  • Opened up the Visual Studio Installer program — This should force VS to check for updates, instead of waiting for it to notice that an update was available. It still took a little while (10 mins) for 15.3 to become available, but I clicked the update button as soon as it was available

  • Installed the .NET Core 2.0 SDK from here — You have to do this step separately at the moment. Once this is installed, the .NET Core 2.0 templates will light up in Visual Studio.

With both of these installed I decided on a quick test to make sure everything was running smoothly. I’d create a basic app using new 2.0 templates.

Creating a new ASP.NET Core 2.0 web app

The File > New Project experience is pretty much the same in ASP.NET Core 2.0, but there are some additional templates available after you choose ASP.NET Core Web Application. If you switch the framework version to ASP.NET Core 2.0, you’ll see some new templates appear, including SPA templates for Angular and React.js:

New ASP.NET Core web application

I left everything at the defaults — no Docker support enabled, no authentication — and selected Web Application (Model-View-Controller).

Note that the templates have been renamed a little. The Web Application template creates a new project using Razor pages, while the Web Application (Model-View-Controller) template creates a template using separate controllers.

Click OK, and wait for the template to scaffold… and …

Visual Studio broken

Oh dear. What’s going on here?

So, there was clearly a problem creating the solution. My first thought was that it was a bug in the new VS 2017 update. A little odd seeing as noone else on Twitter seemed to have mentioned it, but not overly surprising given it had just been released. I should expect some kinks right?

A quickgoogling for the error, turned up this issue, but that seemed to suggest the error was an old one that had been fixed.

I gave it a second go, but sure enough, the same error occurred. Clicking OK left me with a solution with no projects.

Solution view

The project template was created successfully on disk, so I thought, why not just add it to the solution directly: Right Click on the solution file Add > Existing Project?

Error adding

Hmmm, so definitely something significantly wrong here…

Check your global.json

The error was complaining that the SDK was not found. Why would that happen? I had definitely installed the .NET Core 2.0 SDK, and VS could definitely see it, as it had shown me the 2.0 templates.

It was at this point I had an epiphany. A while back, when experimenting with a variety of preview builds, I had recurring issues when I would switch back and forth between preview projects and ASP.NET Core 1.0 projects.

To get round the problem, I created a sub folder in my Repos folder for preview builds, and dropped a global.json into the folder for the newer SDK, and placed the following global.json in the root of my Repos folder:

{
  "sdk": {
    "version": "1.0.0"
  }
}

Any time I created a project in the Previews folder, it would use the preview SDK, but a project created anywhere else would use the stable 1.0.0 SDK. This was the route of my problem.

I was trying to create an ASP.NET Core 2.0 project in a folder tied to the 1.0.0 SDK. That older SDK doesn’t support the new 2.0 projects, so VS was borking when it tried to load the project.

The simple fix was to either delete the global.json entirely (the highest SDK version will be used in that case), or update it to 2.0.0.

In general, you can always use the latest version of the SDK to build your projects. The 2.0.0 SDK can be used to build 1.0.0 projects.

After updating the global.json, VS was able to add the existing project, and to create new projects with no issues.

Visual Studio working

Summary

I was running into an issue where creating a new ASP.NET Core 2.0 project was giving me an error The SDK ‘Microsoft.Net.Sdk.Web’ specified could not be found, and leaving me unable to open the project in Visual Studio. The problem was the project was created in a folder that contained a global.json file, tying the SDK version to 1.0.0.

Deleting the global.json, or updating it to 2.0.0, fixed the issue. Be sure to check parent folders too — if any parent folder contains a global.json, the SDK version specified in the «closest» folder will be used.

Понравилась статья? Поделить с друзьями:
  • Error msb4057 the target build does not exist in the project
  • Error msb4025 не удалось загрузить файл проекта
  • Error msb4019 импортированный проект c microsoft cpp default props не обнаружен
  • Error msb4018 непредвиденная ошибка при выполнении задачи resolvepackageassets
  • Error msb4018 the vcmessage task failed unexpectedly