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

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

问题描述

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

I'm trying to build a solution using msbuild command line and I keep getting this error:

错误 MSB4236:找不到指定的 SDK 'Microsoft.NET.Sdk'.

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

推荐答案

我在尝试安装 .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 Filesdotnetsdk2.0.0Sdks.

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.

基本上,如果您的 .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天全站免登陆