在GitHub Packages上列出NuGet包

7

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

> 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能够列出这些包吗?
2个回答

7

这种行为是由于不是所有nuget服务器都公开相同的API集。可能实现的完整API集在此处定义

我们将nuget.org的服务索引与GitHub的进行比较。nuget.org的服务索引位于此处,其中包含非常广泛的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提供的此处的一个版本只包含一组更加有限的受支持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.exe list所需的API由nuget.org支持,而不是GitHub,这解释了控制台中所述的警告。

我猜这就是为什么 Visual Studio 2019 的包管理器工具不能使用 GPR 源的原因? - Crono
看起来nuget.exe客户端的“list”功能仍然只使用旧的NuGet v2搜索API。当使用v3源时,需要在其index.json中列出“LegacyGallery”资源,指向V2 API端点的前缀,如“Search()”。 - Zastai
有人找到了缓解方法吗? - twinlakes

2

作为解决方法,如果你知道部分名称,至少可以找到一个包或一组包的最新版本

我知道这不是一个解决方案:它不同于获取所有可用包的列表。但它给你重要的信息:是否有一个比你当前版本更高的新包可用。

命令:

nuget search "XYZ" -Source "https://nuget.pkg.github.com/Company-Name/index.json" -PreRelease

用已知包的子字符串替换XYZ。用你公司的名称或位置包含index.json的地方来替换Company-Name

选项-PreRelease的作用是包括预发布版本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接