Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete NuGet packages from Visual Studio Online Package Feed instead of Unlist

Is it possible to delete NuGet packages from a Visual Studio Online package feed?

I've setup CI on Visual Studio Online using the Build Tasks for a dotnet core project.

One of the steps is to pack all the projects in the solution as NuGet packages and push these to the package feed.

The build is working fine, however in my first attempt in the pack and push build steps I used a **/.csproj wildcard instead of src/**/.csproj. So it packed and pushed all my test projects too that were under tests/**.

I'd like to delete these packages from the feed. The only option I could find in the UI was to unlist the packages. But the packages still exist after this operation.

I also tried to delete the packages through the CLI: nuget delete. But it just does the same as unlist.

Has anyone been able to delete their packages?

like image 410
shotor Avatar asked Jul 05 '17 14:07

shotor


1 Answers

Yes, this is possible out-of-the-box with VSTS' Package Management. Note that there is a difference between unlisting and deleting, which I'll elaborate on further.

The TL;DR story for deleting existing packages from VSTS Package Management is that you must be the 'owner' of a package OR have a 'Project Admin'-like role in order to delete it. To unlist a package, you only require the 'contributor' role. For both options, simply go the package details in VSTS and select the appropriate option from the menu under the ellipses:

Delete package screenshot

Now for some background info which might be useful. There is some official documentation available on visualstudio.com:

There are two options available to remove a version of a NuGet package from a feed.

Unlist: unlisting a version of a package modifies how the package appears in NuGet clients (see the NuGet docs for a full description of how unlist works). Unlisting a version can help you prevent new usage of it without breaking dependent projects and builds.

Delete: Deleting a version of a package makes it permanently unavailable for install or restore.

Unlist and delete both respect feed immutability. Once you publish a particular version of a package to a feed, that version number is permanently reserved. You cannot upload a newer revision package with that same version number, or delete it and upload a new package at the same version.

The important part here is "feed immutability", which according to the canon, translates to:

Once you publish a particular version of a package to a feed, that version number is permanently reserved. You cannot upload a newer revision package with that same version number, or delete it and upload a new package at the same version.

The documentation also confirms, as a footnote at the bottom, what you already discovered about nuget.exe:

Currently, NuGet.exe can only unlist packages; Team Services and TFS interpret nuget.exe delete as an unlist operation to be consistent with NuGet.org. To delete a package, you must use either the REST APIs or the web interface.

Doing it programatically should therefor either be done through the REST API or the VSTS admin section, as described above. NuGet.exe can only be used for unlisting - not deleting.

With all of that taken into consideration, with VSTS you can delete packages but - as always - think twice before you do so. Remember the LeftPad debacle? ;)

like image 139
Juliën Avatar answered Sep 21 '22 12:09

Juliën