NuGet 推送抛出 PackageExistsAsDeletedException

NuGet Push throws PackageExistsAsDeletedException

我正在测试 VSTS 托管的 NuGet 提要,并创建了一个 NuPkg 并将其发布到提要,名称为:SomeComponent.2.1.0.npkg

我想重新测试我对发布定义所做的更改,所以我从提要中删除了包,并清空了回收站。

但现在当我尝试发布时收到错误消息:

Error: An unexpected error occurred while trying to push the package with VstsNuGetPush.exe. Exit code(1) and error(Error:
Microsoft.VisualStudio.Services.NuGet.WebApi.Exceptions.PackageExistsAsDeletedException: The version 2.1.0 of SomeComponent has been deleted. It cannot be restored or pushed.
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.HandleResponse(HttpResponseMessage response)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VstsNuGetPush.PackageAdder.AddPackageToFeed(String feedName, BlobIdentifierWithBlocks blobId)
   at VstsNuGetPush.VstsNuGetPushOperation.AddPackageToFeed(BlobIdentifierWithBlocks blobId)
   at VstsNuGetPush.VstsNuGetPushOperation.Execute(Stream stream)
   at VstsNuGetPush.VstsNuGetPushCommand.MainCore(ILogger logger)
   at VstsNuGetPush.VstsNuGetPushCommand.Main())

Packages failed to publish

如果我删除了包并清空了回收站,还有什么能保留我之前发布过这个包的知识?

此外,如果我重新发布一个包,它为什么要关心,我不能直接覆盖那里的东西吗?

无法将已删除的 nuget 包再次推送到 VSTS 源,因为您推送了与已删除包相同的版本

并且相同版本的已删除包不应该再次推送的保护机制,因为这可能会导致使用包版本的项目混淆。下面是一个示例,如果可以再次推送已删除的包,则会导致意外结果:

假设 project1 使用版本 2.1.0 的 nuget 包 SomeComponent。当您在 VSTS 提要中删除此包时,project1 只会找到版本 2.1.0 的 nuget 包 SomeComponent 不可用。但是如果SomeComponent同版本2.1.0的包2.1.0(这个.pkg和被删除的相比有很大的不同)可以再次push,会造成意想不到的result/error for project1.

所以,简而言之,你应该为同一个 nuget 包推送一个与删除版本不同的版本(例如推送 SomeComponent 版本为 2.1.1 在上面的例子中)。