首页 > 解决方案 > ASP.NET Core:未找到 global.json 版本 2.1.400 的兼容 SDK 版本

问题描述

我的解决方案中有一个面向 .NET Core 2.1 的 ASP.NET Core 项目。我在解决方案级别添加了一个 global.json 文件:

{
  "sdk": {
    "version": "2.1.400"
  }
}

在 Team City 代理上,我安装了 MSBuild Tools 2017 (15.8.1),包括 .NET Core Build Tools。

从命令行我可以看到 SDK 2.1.400 安装在代理上:

>dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]

但是,在 Team City 上构建解决方案失败并出现以下错误:

dashboard.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
Dashboard.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
A compatible SDK version for global.json version: [2.1.400] from [X:\agent-1\sandbox1\global.json] was not found

知道为什么在使用 MSBuild 构建时找不到 SDK 2.1.400,因为它存在于 SDK 列表中?

标签: asp.net-coremsbuild

解决方案


我终于发现dotnet在 Team City 上运行时不被识别为命令(尽管dotnet在相同的 Windows 帐户下被识别为提示符中的命令)。

我的解决方案是PATH使用 Team City 参数更新环境变量:

Name: env.PATH
Kind: Environment Variable
Value: C:\Program Files\dotnet;%env.PATH%

它现在按预期工作。


推荐阅读