dotnet SDK 2.2.104 不编译 .NET Core 2.2

dotnet SDK 2.2.104 don't compile .NET Core 2.2

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

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

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

dotnet 构建:

C:\Program Files\dotnet\sdk.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.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>

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

为了解决这个问题,我们需要将 MSBuildSDKsPath 重新定位到我们想要的 SDK 版本,或者完全删除这个变量。

之前:

set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk.1.500\Sdks

之后:

set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk.2.104\Sdks