Unable to delete NuGet package on server

By | September 29, 2015

Today I was trying to clean up some old packages from the Nuget server. And this happened. Nuget delete command failed to delete packages from the Nuget Server. The nuget server I am talking about is the local one which I configured.

Deletion was failing for me despite the documentation saying that is should succeed.

I was getting errors like this:

C:\Users\HeroThatNeverWas>nuget delete MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 -ApiKey DieHard -Source http://MyOwnNugetServer/ -Verbosity detailed
MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 will be deleted from the 'http://MyOwnNugetServer/'. Would you like to continue? (y/N) y
Deleting MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 from the 'http://MyOwnNugetServer/'.
DELETE http://MyOwnNugetServer/api/v2/package/MahApps.Metro.SimpleChildWindow/1.3.0-ALPHA001
System.InvalidOperationException: Failed to process request. 'Internal Server Error'.
The remote server returned an error: (500) Internal Server Error.. ---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at NuGet.RequestHelper.GetResponse()
   at NuGet.HttpClient.GetResponse()
   at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable`1 expectedStatusCode)
   --- End of inner exception stack trace ---
   at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable`1 expectedStatusCode)
   at NuGet.PackageServer.DeletePackageFromServer(String apiKey, String packageId, String packageVersion)
   at NuGet.PackageServer.DeletePackage(String apiKey, String packageId, String packageVersion)
   at NuGet.Commands.DeleteCommand.ExecuteCommand()
   at NuGet.Commands.Command.Execute()
   at NuGet.Program.Main(String[] args)

I finally nailed it down to the permissions on the packages in the Packages folder. (This folder is usually under Server folder in your Nuget Server install. Unless you have changed the web.config to make some other folder as your package destination.)

It was “Read” and “Read and Execute” for normal users.
Just for testing I used the “Full Control” sledgehammer.
And it worked.

C:\Users\HeroThatNeverWas>nuget delete MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001  -ApiKey DieHard -Source http://MyOwnNugetServer/ -Verbosity detailed
MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 will be deleted from the 'http://MyOwnNugetServer/'. Would you like to continue? (y/N) y
Deleting MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 from the 'http://MyOwnNugetServer/'.
DELETE http://MyOwnNugetServer/api/v2/package/MahApps.Metro.SimpleChildWindow/1.3.0-ALPHA001
MahApps.Metro.SimpleChildWindow 1.3.0-ALPHA001 was deleted successfully.

And of course before I am blasted for deleting packages from the Nuget server I will make it clear that it was Beta packages I was cleaning up.
And yes, rather than just deleting them, I move them to a separate folder on my server. Delisting is also an option though users can install the delisted packaged via commandline.

Hopefully it saved you sometime.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.