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

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

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

点网构建

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>
4

1 回答 1

2

感谢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
于 2019-03-12T08:57:22.973 回答