dotnet SDK 2.2.104无法编译.NET Core 2.2

时间:2019-03-12 08:57:23

标签: .net-core dotnet-cli dotnet-sdk

  1. 我有一个.NET Sdk 2.1及更低版本。
  2. 我安装了sdk2.2和sdk3。
  3. 我删除了sdk3

现在,VS17成功构建并测试了我的解决方案。

但是从dotnet-cli的命令行,我无法编译解决方案,因为他说他是sdk2.1

dotnet构建

C:\Program Files\dotnet\sdk\2.1.500\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2.  Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2. [C:\Users\.......\WebApi.csproj]

Build FAILED.

dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.2.104
 Commit:    73f036d4ac

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.104\

Host (useful for support):
  Version: 2.2.2
  Commit:  a4fd7b2c84

.NET Core SDKs installed:
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.2.104 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

WebApi.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    .
    .
    .
  </PropertyGroup>
</Project>

1 个答案:

答案 0 :(得分:0)

感谢livarcocc,我们知道问题出在MSBuildSDKsPath环境变量中,该变量仍指向sdk2.1

为解决此问题,我们需要将MSBuildSDKsPath重定向到所需的SDK版本,或完全删除此变量。

之前:

set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\2.1.500\Sdks

之后:

set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\2.2.104\Sdks