2017-09-16 44 views
7

我想使用的MSBuild命令行建立一个解决方案,我不断收到此错误:MSBUILD抛出错误:SDK“Microsoft.NET.Sdk”指定找不到

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。

这是我使用的命令:

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) 
+0

我的猜测是该项目引用该SDK。为了构建它,它必须被安装。编译器如何才能打印和其他所有内容? – Christopher

+0

@Christopher我用完整的日志编辑了帖子。是的,我的项目引用该SDK,但我试图恢复它。 –

+0

按照我的想法。编译器找不到SDK。您需要将它安装到编译器中进行构建。理想情况下,你选择了默认位置。如果没有,您可能需要编辑该项目,以便在适当的位置查找SDK。 – Christopher

回答

11

我与.net核2.0安装玩耍,看似插科打诨之后遇到此错误向上。我会得到这个相同的错误dotnet restore,dotnet builddotnet msbuild。基本上,任何涉及.Net Core和msbuild的。

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

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

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

相关问题