【问题标题】:List nuget packages on GitHub Packages在 GitHub Packages 上列出 nuget 包
【发布时间】:2020-04-12 19:15:11
【问题描述】:

我在 GitHub Packages 上托管了 nuget 包。然后,当我尝试使用nuget.exe 列出 github nuget 提要中的包时,它告诉我它无法列出提要中的包:

> nuget list -Source "https://nuget.pkg.github.com/mabead/index.json"
WARNING: This version of nuget.exe does not support listing packages from package source 'https://nuget.pkg.github.com/mabead/index.json'.
No packages found.

请注意,当我使用单击“为解决方案管理 Nuget 包”后打开的窗口时,这些包已正确列出在 Visual Studio 中。所以提要有效,但不适用于 nuget cli。

我使用的是 nuget.exe 5.5.1 版。

知道我用什么来使用 CLI 列出包吗?

【问题讨论】:

    标签: nuget github-package-registry


    【解决方案1】:

    这种行为是由于并非所有 nuget 服务器都公开相同的 API 集这一事实造成的。全套可能实现的 API 定义为here

    我们对比一下 nuget.org 的服务索引和 GitHub 的服务索引。 nuget.org 的一个可用 here,它包含一组非常广泛的 API。

    {
      "version": "3.0.0",
      "resources": [
        {
          "@id": "https://azuresearch-usnc.nuget.org/query",
          "@type": "SearchQueryService",
          "comment": "Query endpoint of NuGet Search service (primary)"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/query",
          "@type": "SearchQueryService",
          "comment": "Query endpoint of NuGet Search service (secondary)"
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService",
          "comment": "Autocomplete endpoint of NuGet Search service (primary)"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService",
          "comment": "Autocomplete endpoint of NuGet Search service (secondary)"
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/",
          "@type": "SearchGalleryQueryService/3.0.0-rc",
          "comment": "Azure Website based Search Service used by Gallery (primary)"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/",
          "@type": "SearchGalleryQueryService/3.0.0-rc",
          "comment": "Azure Website based Search Service used by Gallery (secondary)"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-semver1/",
          "@type": "RegistrationsBaseUrl",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored"
        },
        {
          "@id": "https://api.nuget.org/v3-flatcontainer/",
          "@type": "PackageBaseAddress/3.0.0",
          "comment": "Base URL of where NuGet packages are stored, in the format https://api.nuget.org/v3-flatcontainer/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg"
        },
        {
          "@id": "https://www.nuget.org/api/v2",
          "@type": "LegacyGallery"
        },
        {
          "@id": "https://www.nuget.org/api/v2",
          "@type": "LegacyGallery/2.0.0"
        },
        {
          "@id": "https://www.nuget.org/api/v2/package",
          "@type": "PackagePublish/2.0.0"
        },
        {
          "@id": "https://www.nuget.org/api/v2/symbolpackage",
          "@type": "SymbolPackagePublish/4.9.0",
          "comment": "The gallery symbol publish endpoint."
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/query",
          "@type": "SearchQueryService/3.0.0-rc",
          "comment": "Query endpoint of NuGet Search service (primary) used by RC clients"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/query",
          "@type": "SearchQueryService/3.0.0-rc",
          "comment": "Query endpoint of NuGet Search service (secondary) used by RC clients"
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService/3.0.0-rc",
          "comment": "Autocomplete endpoint of NuGet Search service (primary) used by RC clients"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService/3.0.0-rc",
          "comment": "Autocomplete endpoint of NuGet Search service (secondary) used by RC clients"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-semver1/",
          "@type": "RegistrationsBaseUrl/3.0.0-rc",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored used by RC clients. This base URL does not include SemVer 2.0.0 packages."
        },
        {
          "@id": "https://www.nuget.org/packages/{id}/{version}/ReportAbuse",
          "@type": "ReportAbuseUriTemplate/3.0.0-rc",
          "comment": "URI template used by NuGet Client to construct Report Abuse URL for packages used by RC clients"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-semver1/{id-lower}/index.json",
          "@type": "PackageDisplayMetadataUriTemplate/3.0.0-rc",
          "comment": "URI template used by NuGet Client to construct display metadata for Packages using ID"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-semver1/{id-lower}/{version-lower}.json",
          "@type": "PackageVersionDisplayMetadataUriTemplate/3.0.0-rc",
          "comment": "URI template used by NuGet Client to construct display metadata for Packages using ID, Version"
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/query",
          "@type": "SearchQueryService/3.0.0-beta",
          "comment": "Query endpoint of NuGet Search service (primary) used by beta clients"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/query",
          "@type": "SearchQueryService/3.0.0-beta",
          "comment": "Query endpoint of NuGet Search service (secondary) used by beta clients"
        },
        {
          "@id": "https://azuresearch-usnc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService/3.0.0-beta",
          "comment": "Autocomplete endpoint of NuGet Search service (primary) used by beta clients"
        },
        {
          "@id": "https://azuresearch-ussc.nuget.org/autocomplete",
          "@type": "SearchAutocompleteService/3.0.0-beta",
          "comment": "Autocomplete endpoint of NuGet Search service (secondary) used by beta clients"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-semver1/",
          "@type": "RegistrationsBaseUrl/3.0.0-beta",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored used by Beta clients. This base URL does not include SemVer 2.0.0 packages."
        },
        {
          "@id": "https://www.nuget.org/packages/{id}/{version}/ReportAbuse",
          "@type": "ReportAbuseUriTemplate/3.0.0-beta",
          "comment": "URI template used by NuGet Client to construct Report Abuse URL for packages"
        },
        {
          "@id": "https://www.nuget.org/packages/{id}/{version}?_src=template",
          "@type": "PackageDetailsUriTemplate/5.1.0",
          "comment": "URI template used by NuGet Client to construct details URL for packages"
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-gz-semver1/",
          "@type": "RegistrationsBaseUrl/3.4.0",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored in GZIP format. This base URL does not include SemVer 2.0.0 packages."
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-gz-semver2/",
          "@type": "RegistrationsBaseUrl/3.6.0",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
        },
        {
          "@id": "https://api.nuget.org/v3/registration5-gz-semver2/",
          "@type": "RegistrationsBaseUrl/Versioned",
          "clientVersion": "4.3.0-alpha",
          "comment": "Base URL of Azure storage where NuGet package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
        },
        {
          "@id": "https://api.nuget.org/v3-index/repository-signatures/4.7.0/index.json",
          "@type": "RepositorySignatures/4.7.0",
          "comment": "The endpoint for discovering information about this package source's repository signatures."
        },
        {
          "@id": "https://api.nuget.org/v3-index/repository-signatures/5.0.0/index.json",
          "@type": "RepositorySignatures/5.0.0",
          "comment": "The endpoint for discovering information about this package source's repository signatures."
        },
        {
          "@id": "https://api.nuget.org/v3/catalog0/index.json",
          "@type": "Catalog/3.0.0",
          "comment": "Index of the NuGet package catalog."
        }
      ],
      "@context": {
        "@vocab": "http://schema.nuget.org/services#",
        "comment": "http://www.w3.org/2000/01/rdf-schema#comment"
      }
    }
    

    GitHub 上可用的 here 包含一组更有限的受支持 API:

     {
          "version": "3.0.0-beta.1",
          "resources": [
            {
              "@id": "https://nuget.pkg.github.com/mabead/download",
              "@type": "PackageBaseAddress/3.0.0",
              "comment": "Get package content (.nupkg)."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead/query",
              "@type": "SearchQueryService",
              "comment": "Filter and search for packages by keyword."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead/query",
              "@type": "SearchQueryService/3.0.0-beta",
              "comment": "Filter and search for packages by keyword."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead/query",
              "@type": "SearchQueryService/3.0.0-rc",
              "comment": "Filter and search for packages by keyword."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead",
              "@type": "PackagePublish/2.0.0",
              "comment": "Push and delete (or unlist) packages."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead",
              "@type": "RegistrationsBaseUrl",
              "comment": "Get package metadata."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead",
              "@type": "RegistrationsBaseUrl/3.0.0-beta",
              "comment": "Get package metadata."
            },
            {
              "@id": "https://nuget.pkg.github.com/mabead",
              "@type": "RegistrationsBaseUrl/3.0.0-rc",
              "comment": "Get package metadata."
            }
          ]
        }
    

    因此,nuget.org 支持执行nuget.exe list 所需的 API,但 GitHub 不支持,因此解释了控制台中解释的警告。

    【讨论】:

    • 我认为这就是为什么Visual Studio 2019 的包管理器工具不适用于 GPR 源? ?
    • 看起来 nuget.exe 客户端的 list 功能仍仅使用较旧的 NuGet v2 搜索 API。使用 v3 源时,需要在其 index.json 中列出 LegacyGallery 资源,指向 V2 API 端点的前缀,例如 Search()
    • 有人找到缓解措施了吗?
    猜你喜欢
    • 2022-11-24
    • 2023-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 2022-06-15
    • 2021-04-08
    相关资源
    最近更新 更多