MSBUILD throws error: The SDK 'Microsoft.NET.S

2020-06-30 08:59发布

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)

7条回答
smile是对你的礼貌
2楼-- · 2020-06-30 09:28

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

查看更多
等我变得足够好
3楼-- · 2020-06-30 09:32

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"  }}
查看更多
The star\"
4楼-- · 2020-06-30 09:33

Got the same issue when tried to install x64 .Net Core SDK installer. Event the following dotnet --info command shows me that no SDK found.

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

查看更多
SAY GOODBYE
5楼-- · 2020-06-30 09:34

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

查看更多
太酷不给撩
6楼-- · 2020-06-30 09:41

May be you encourated the error also after installing .net core SDK 3.0, You have to check the environment variable MSBuildSDKsPath after every install of a new SDK. It must traget the SDK you use to create your project. I use VS2017 with Windows 10.

for 2.2 SDK

C:\Program Files\dotnet\sdk\2.2.104\Sdks

for 3.0 preview

C:\Program Files\dotnet\sdk\3.0.100-preview3-010431\Sdks 
查看更多
女痞
7楼-- · 2020-06-30 09:43

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.

查看更多
登录 后发表回答