从NuGetV3 API获取一个包

24

我有兴趣用非.NET语言编写NuGet v3 API的客户端库。

获取软件包所需的请求是什么,响应看起来如何?

例如:

GET {package-versions} GET {package-version}

请同时提供覆盖此场景的官方文档链接。


1
搜索外部链接显然是不相关的,但如果您找到信息,请考虑更新标签的维基页面(http://stackoverflow.com/tags/nuget/info)。 - Alexei Levenkov
你唯一的希望很可能是这段C#代码:https://github.com/NuGet/NuGet.Client/tree/dev/src/NuGet.Core/NuGet.Protocol.Core.v3 - Lex Li
礼貌地请求文档 https://github.com/NuGet/Home/issues/4062 - Colonel Panic
https://docs.nuget.org/ndocs/api/nuget-api-v3 - Yishai Galatzer
1个回答

34

这里是官方的NuGet V3 API文档。API由多个协议组成,包括:

  1. PackageBaseAddress - 包含实际软件包及其清单文件(nuspec)的存储库。
  2. Service Index - 用于客户端发现NuGet服务。
  3. Search Service - 供客户端搜索NuGet软件包使用。
  4. Registration - 基于json-LD结构存储软件包元数据。这包括软件包的内容、依赖关系、描述等...

例如,假设您想要下载“Newtonsoft.Json”软件包:

  1. 获取服务索引:`GET https://api.nuget.org/v3/index.json

响应包含PackageBaseAddress(也称为扁平容器,但实际上是分层的而不是扁平的 :))的地址:

{
  "@id": "https://api.nuget.org/v3-flatcontainer/",
  "@type": "PackageBaseAddress/3.0.0",
  "comment": "Base URL of Azure storage where NuGet package registration info for DNX is stored, in the format https://api.nuget.org/v3-flatcontainer/{id-lower}/{version-lower}.{version-lower}.nupkg"
},
  1. 使用@id提供的uri作为基础uri列出所需包的版本:GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json,请注意这个uri可能会变化,且不是API的一部分。
  2. 使用相同的基础uri下载包:GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/6.0.4/newtonsoft.json.6.0.4.nupkg

您还可以查看NuGet客户端。客户端的源代码在这里;您需要从NuGet.CommandLine项目开始,并逐步向下深入。


太棒了,非常有启发性。感谢您的回复! - James Ko

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