的 tools.json 的终结点

目前,可通过几种方法以可编写脚本的方式在计算机上获取最新版本的 nuget.exe。 例如,可从 nuget.org 下载和提取 NuGet.CommandLine 包。此操作存在一定复杂性,因为它要么要求你已有 nuget.exe(适用于 nuget.exe install),要么必须使用基本解压缩工具来解压缩 .nupkg,并在其中查找二进制文件。

如果已有 nuget.exe,也可使用 nuget.exe update -self,但这也要求拥有 nuget.exe 的现有副本。 此方法还会将 nuget.exe 更新到最新版本。 它不允许使用特定版本。

tools.json 终结点可用于解决引导问题并控制下载的 nuget.exe 版本。 这可用于 CI/CD 环境或自定义脚本,从而发现和下载任意已发布的 nuget.exe 版本。

可使用未经身份验证的 HTTP 请求(例如,PowerShell 或 wget 中的 Invoke-WebRequest)来提取 tools.json 终结点。 可使用 JSON 反序列化程序对其进行分析,且后续 nuget.exe 下载 URL 也可使用未经身份验证的 HTTP 请求来提取。

可使用 GET 方法提取该终结点:

GET https://dist.nuget.org/tools.json

终结点的 JSON 架构可在此处获取:

GET https://dist.nuget.org/tools.schema.json

响应

响应是指包含 nuget.exe 的所有可用版本的 JSON 文档。

根 JSON 对象具有以下属性:

名称 类型​​ 必须
nuget.exe 对象数组

nuget.exe 数组中的每个对象均具有以下属性:

名称 类型​​ 必须 说明
版本 string SemVer 2.0.0 字符串
url string 用于下载此版本 nuget.exe 的绝对 URL
阶段 (stage) string 枚举字符串
已上传 string 提供该版本的时间的大致 ISO 8601 时间戳

此数组中的项目将按 SemVer 2.0.0 降序排序。 此保证旨在减轻对最高版本号感兴趣的客户端的负担。 但是,这确实意味着该列表未按时间顺序进行排序。 例如,如果较低的主版本晚于主要版本提供,则提供的此版本不会显示在列表顶部。 如果需要按时间戳发布的最新版本,只需按 uploaded 字符串对数组进行排序即可。 这很有效,因为 uploaded 时间戳采用 ISO 8601 格式,因而可用字母排序(即简易字符串排序)方式按时间顺序排序。

stage 属性指示了此版本的工具的审查方式。

阶段 含义
EarlyAccessPreview 下载网页上尚不可见,且应由合作伙伴对其进行验证
已发布 已在下载站点上提供,但尚不建议广泛使用
ReleasedAndBlessed 已在下载站点上提供,且建议使用

使用最新推荐版本的一种简单方法是采用列表中 stage 值为 ReleasedAndBlessed 的第一个版本。 这很有效,因为版本将按 SemVer 2.0.0 顺序进行排序。

nuget.org 上的 NuGet.CommandLine 包通常仅随 ReleasedAndBlessed 版本一起更新。

示例请求

GET https://dist.nuget.org/tools.json

示例响应

{
    "nuget.exe": [
        {
            "version": "4.8.0-preview3",
            "url": "https://dist.nuget.org/win-x86-commandline/v4.8.0-preview3/nuget.exe",
            "stage": "EarlyAccessPreview",
            "uploaded": "2018-07-06T23:00:00.0000000Z"
        },
        {
            "version": "4.7.1",
            "url": "https://dist.nuget.org/win-x86-commandline/v4.7.1/nuget.exe",
            "stage": "ReleasedAndBlessed",
            "uploaded": "2018-08-10T23:00:00.0000000Z"
        },
        {
            "version": "4.6.1",
            "url": "https://dist.nuget.org/win-x86-commandline/v4.6.1/nuget.exe",
            "stage": "Released",
            "uploaded": "2018-03-22T23:00:00.0000000Z"
        },
        {
            "version": "3.5.0",
            "url": "https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe",
            "stage": "ReleasedAndBlessed",
            "uploaded": "2016-12-19T15:30:00.0000000-08:00"
        },
        {
            "version": "2.8.6",
            "url": "https://dist.nuget.org/win-x86-commandline/v2.8.6/nuget.exe",
            "stage": "ReleasedAndBlessed",
            "uploaded": "2015-09-01T12:30:00.0000000-07:00"
        }
    ]
}