MSBUILD引发错误:找不到指定的SDK'Microsoft.NET.Sdk' [英] MSBUILD throws error: The SDK 'Microsoft.NET.Sdk' specified could not be found

查看:1166
本文介绍了MSBUILD引发错误:找不到指定的SDK'Microsoft.NET.Sdk'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用msbuild命令行构建解决方案,但不断出现此错误:

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.

msbuild的版本是Microsoft Visual Studio 2017工具中的最新版本.我正在使用Windows Server 2012 R2,并且该项目使用.NET Core 2.0.

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

完整日志:

    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)

推荐答案

在玩完.Net Core 2.0安装并将其弄乱之后,我遇到了此错误.对于dotnet restoredotnet builddotnet msbuild,我会得到同样的错误.本质上,任何涉及.Net Core和msbuild的事物.

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.

发生错误是因为MSBuildSDKsPath环境变量仍指向旧的.Net Core 1.1 SDK.

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

为解决此问题,我手动将MSBuildSDKsPath环境变量设置为指向2.0.0的SDK路径,对于x64,对于我来说,该路径为:C:\Program Files\dotnet\sdk\2.0.0\Sdks.

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.

基本上,如果.csproj中有Sdk="Microsoft.NET.Sdk",则在MSBuildSDKsPath位置应存在一个具有相同名称的文件夹.

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

这篇关于MSBUILD引发错误:找不到指定的SDK'Microsoft.NET.Sdk'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆