推送和删除Push and Delete

可以推送、 删除 (或取消列出,具体取决于服务器实现),并重新列出包使用 NuGet V3 API。It is possible to push, delete (or unlist, depending on the server implementation), and relist packages using the NuGet V3 API. 这些操作所基于的中断PackagePublish资源中找到服务索引These operations are based off of the PackagePublish resource found in the service index.

版本管理Versioning

以下@type使用值:The following @type value is used:

@type 值@type value 说明Notes
PackagePublish/2.0.0PackagePublish/2.0.0 初始版本The initial release

基 URLBase URL

以下 Api 的基 URL 是的值@id的属性PackagePublish/2.0.0包源中的资源服务索引The base URL for the following APIs is the value of the @id property of the PackagePublish/2.0.0 resource in the package source's service index. 以下文档中,使用 nuget.org 的 URL。For the documentation below, nuget.org's URL is used. 请考虑https://www.nuget.org/api/v2/package作为占位符@id服务索引中找到的值。Consider https://www.nuget.org/api/v2/package as a placeholder for the @id value found in the service index.

请注意此 URL 指向与旧的 V2 推送终结点相同的位置,因为协议是相同。Note that this URL points to the same location as the legacy V2 push endpoint since the protocol is the same.

HTTP 方法HTTP methods

PUTPOSTDELETE此资源支持 HTTP 方法。The PUT, POST and DELETE HTTP methods are supported by this resource. 有关每个终结点上支持哪些方法,请参阅下面。For which methods are supported on each endpoint, see below.

将包推送Push a package

备注

nuget.org 已其他要求与推送终结点进行交互。nuget.org has additional requirements for interacting with the push endpoint.

nuget.org 支持推送新的包使用以下 API。nuget.org supports pushing new packages using the following API. 如果已存在具有提供的 ID 和版本的包,nuget.org 将拒绝推送。If the package with the provided ID and version already exists, nuget.org will reject the push. 其他包源可能支持替换现有的包。Other package sources may support replacing an existing package.

PUT https://www.nuget.org/api/v2/package

请求参数Request parameters

名称Name In 类型Type 必需Required 说明Notes
X-NuGet-ApiKeyX-NuGet-ApiKey HeaderHeader stringstring yes 例如,X-NuGet-ApiKey: {USER_API_KEY}For example, X-NuGet-ApiKey: {USER_API_KEY}

API 密钥是从包源获得由用户和配置到客户端不透明的字符串。The API key is an opaque string gotten from the package source by the user and configured into the client. 强制要求任何特定字符串格式,但 API 密钥的长度不应超过合理的大小,为 HTTP 标头值。No particular string format is mandated but the length of the API key should not exceed a reasonable size for HTTP header values.

请求正文Request body

请求正文必须采用以下形式:The request body must come in the following form:

多部分窗体数据Multipart form data

请求标头Content-Typemultipart/form-data和请求正文中的第一项是推送.nupkg 的原始字节。The request header Content-Type is multipart/form-data and the first item in the request body is the raw bytes of the .nupkg being pushed. 多部分正文中后面的项将被忽略。Subsequent items in the multipart body are ignored. 将忽略的文件的名称或任何其他标头的多部分项。The file name or any other headers of the multipart items are ignored.

响应Response

状态代码Status Code 含义Meaning
201, 202201, 202 已成功推送包The package was successfully pushed
400400 提供的包无效The provided package is invalid
409409 已存在具有提供的 ID 和版本的包A package with the provided ID and version already exists

服务器实现上成功状态代码返回成功推送包时存在差异。Server implementations vary on the success status code returned when a package is successfully pushed.

删除包Delete a package

nuget.org 将解释为包删除请求的"取消列出"。nuget.org interprets the package delete request as an "unlist". 这意味着包仍可用于包的现有使用者,但包不会再出现在搜索结果中或 web 界面中。This means that the package is still available for existing consumers of the package but the package no longer appears in search results or in the web interface. 有关这种做法的详细信息,请参阅删除包策略。For more information about this practice, see the Deleted Packages policy. 其他服务器实现可以自由地解释为硬删除此信号,软删除,或取消列出。Other server implementations are free to interpret this signal as a hard delete, soft delete, or unlist. 例如, NuGet.Server (仅支持较旧的 V2 API 的服务器实现) 支持处理此请求作为未列出或硬删除基于配置选项。For example, NuGet.Server (a server implementation only supporting the older V2 API) supports handling this request as either an unlist or a hard delete based on a configuration option.

DELETE https://www.nuget.org/api/v2/package/{ID}/{VERSION}

请求参数Request parameters

名称Name In 类型Type 必需Required 说明Notes
IdID URLURL stringstring yes 要删除的包 IDThe ID of the package to delete
VERSIONVERSION URLURL stringstring yes 要删除的包的版本The version of the package to delete
X-NuGet-ApiKeyX-NuGet-ApiKey HeaderHeader stringstring yes 例如,X-NuGet-ApiKey: {USER_API_KEY}For example, X-NuGet-ApiKey: {USER_API_KEY}

响应Response

状态代码Status Code 含义Meaning
204204 删除此包,The package was deleted
404404 利用所提供的任何包IDVERSION存在No package with the provided ID and VERSION exists

重新列出包Relist a package

如果某个包未列出,则就可以使该包在使用"重新列出"终结点的搜索结果中再次可见。If a package is unlisted, it is possible to make that package once again visible in search results using the "relist" endpoint. 此终结点有形状删除 (取消列出) 终结点但使用POSTHTTP 方法,而不是DELETE方法。This endpoint has the same shape as the delete (unlist) endpoint but uses the POST HTTP method instead of the DELETE method.

如果包已列出,请求仍会成功。If the package is already listed, the request still succeeds.

POST https://www.nuget.org/api/v2/package/{ID}/{VERSION}

请求参数Request parameters

名称Name In 类型Type 必需Required 说明Notes
IdID URLURL stringstring yes 重新列出包的 IDThe ID of the package to relist
VERSIONVERSION URLURL stringstring yes 重新列出包的版本The version of the package to relist
X-NuGet-ApiKeyX-NuGet-ApiKey HeaderHeader stringstring yes 例如,X-NuGet-ApiKey: {USER_API_KEY}For example, X-NuGet-ApiKey: {USER_API_KEY}

响应Response

状态代码Status Code 含义Meaning
200200 现在,该包列The package is now listed
404404 利用所提供的任何包IDVERSION存在No package with the provided ID and VERSION exists