MSBUILD throws error: The SDK 'Microsoft.NET.Sdk' specified could not be found

71,447

Solution 1

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 Files\dotnet\sdk\2.0.0\Sdks.

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

Solution 2

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

Solution 3

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 Files\dotnet\sdk 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"  }}

Solution 4

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"

Solution 5

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

Share:
71,447
Luiz Gustavo Maia
Author by

Luiz Gustavo Maia

Updated on July 05, 2022

Comments

  • Luiz Gustavo Maia
    Luiz Gustavo Maia almost 2 years

    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

    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:\Projects\MyProject.sln" on node 1 (restore target(s)).
        ValidateSolutionConfiguration:
          Building solution configuration "Release|Any CPU".
        Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (2) on node 1 (restore target(s)).
        C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
        Done Building Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (restore target(s)) -- FAILED.
    
        Build FAILED.
        "C:\Projects\MyProject.sln" (restore target) (1) ->
    "C:\Projects\Kernel\Kernel.csproj" (restore target) (2) ->
      C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
    
    0 Warning(s)
        11 Error(s)
    
  • Razze
    Razze over 5 years
    Thanks, I had to create a new system environment variable as I had no MSBuildSDKsPath then I threw the latest sdk paths in there C:\Program Files\dotnet\sdk\2.1.500\Sdks.
  • Daniel W.
    Daniel W. over 4 years
    I had to add that global.json file but after that the error has gone.
  • KevinM
    KevinM about 4 years
    The error was on our TeamCity build server only. Installing MS Build Tools with .Net Core SDK was not enough. I also had to create the MSBuildSDKsPath and set the value to C:\Program Files\dotnet\sdk\3.1.101\Sdks. Thank you @Sebastian
  • soupy1976
    soupy1976 about 4 years
    I had TeamCity agent running on Windows Server 2008 R2, this worked for me. I did have to restart the machine to get it to recognise the new environment variable
  • Peter PitLock
    Peter PitLock about 4 years
    In my case I had to install ".net core build tools". Its on the initial setup screen of the build tools - i usually skip straight to the individual components.
  • Jordan Parker
    Jordan Parker almost 4 years
    Using TeamCity here & forgot to install .NET Core build tools as part of Visual Studio (MS) Build Tools. Didn't require the path MSBuildSDKsPath and thankful because I'm not trying to maintain that on all my build agents.
  • James Skemp
    James Skemp over 3 years
    Note that the command to create the global.json is dotnet new globaljson --sdk-version 3.1.100. See docs.microsoft.com/en-us/dotnet/core/tools/global-json
  • Branden Barber
    Branden Barber over 3 years
    Can confirm that restarting also fixes this issue in VS Code
  • StrikeAgainst
    StrikeAgainst over 2 years
    VSC 2019 (16.11.4) here, for some reason the .NET Core SDK entry is missing for me. I've been installing .NET SDK instead but the problem still occurs.
  • Yasel
    Yasel over 2 years
    @StrikeAgainst try downloading the .NET Core SDK from the .NET Core download page
  • StrikeAgainst
    StrikeAgainst over 2 years
    I already figured the problem out, I've missed that .NET Core SDK merely had been renamed to .NET SDK, so I was fine actually. The building issues were resolved after I restarted VSC.
  • Mateusz Stępniak
    Mateusz Stępniak over 2 years
    @StrikeAgainst Thanks a lot for figuring it out and letting us know about it
  • ElMatador
    ElMatador over 2 years
    This fixed it for me as I was trying to get a GitHub Runner working on my build server, thanks!
  • Tim
    Tim over 2 years
    Restarting also fixed the problem in JetBrains Rider (version 2021.3).