28

I have added new package to nuget(I'm not talking about adding reference of package into project). I have added new packages to server so that others can consume/use that package in their projects.

Say package name was Parser1.0.0.0.nupkg

Problem is I forgot to add one dependency. Now I want to edit or delete and add correct one again. But I don't want to change its version number.

Anyone knows how to do it?

6 Answers 6

23

Permanently deleting packages is not supported, but you can control how they are listed. (assuming you're talking about nuget.org).

After signing in, in there is additional information on the delete package page. e.g. https://nuget.org/packages/Parser/1.0.0.0/Delete.

Quoting nuget's explanation from the delete package page :

"Why can’t I delete my package? Our policy is to only permanently delete NuGet packages that really need it, such as packages that contain passwords, malicious/harmful code, etc. This policy is very similar to the policies employed by other package managers such as Ruby Gems.

Unlisting the package will remove the package from being available in the NuGet. The package is still available for download as a dependency for three main reasons.

Other packages may depend on that package. Those packages might not necessarily be in this gallery. Ensures that folks using NuGet without committing packages (package restore) will not be broken. Helps ensure that important community owned packages are not mass deleted."

I would suggest unlisting the previous package and bumping the version to 1.0.0.1 after adding the dependency.

3
  • Yep, OP may not want to bump the version number, but when you take your package for a spin in public, you have to obey the rules of the road.
    – Jim Counts
    Jul 25, 2012 at 21:06
  • 4
    Yes, it is possible to delete a package when you published something by misstake. In the eamil you got from NuGet you can click on "contact support" and this is linked to your Package Manage where you can give a reason about why you want to delete it and then give the action to delete it. And done! You only need to agree that your action can affect others by deleting it. Feb 9, 2020 at 12:51
  • For the current policy on package deletion, go here: learn.microsoft.com/en-us/nuget/nuget-org/policies/…. May 11, 2021 at 18:53
14

It is possible for private NuGet servers. Use the NuGet delete command.

nuget delete MyPackage 1.0

Update: This still doesn't address the OP's issue as it doesn't allow you to reuse the version number, because it's still being locked by the server. There is no safe way to permanently delete a specific version of a package.

5
  • 10
    According to this documentation page, the command "Deletes or unlists a package", depending on how the server is configured, so it actually might be possible to reuse the version number. A command like this worked for me: nuget delete MyPackage 1.0 -Source http://package.contoso.com/source -apikey A1B2C3. Jul 19, 2018 at 7:51
  • 1
    Instead of nuget delete, on a private server you can just go to the folder where the package is served from and move that version folder elsewhere.
    – StingyJack
    Oct 18, 2018 at 12:14
  • @StingyJack - We're using TFS as our package repository, so I believe they're all stored in a database...which I don't have access to. I can see where your suggestion would work for a filesystem-based repository (I've used those in the past). Oct 26, 2018 at 18:11
  • @MichaelEarls - TFS On-Premise with a package repo? What version? (im still on 2015.4 - no time to upgrade)
    – StingyJack
    Oct 28, 2018 at 17:10
  • @StingyJack As of this comment, we're using Version 2018 update 3.1 On-Premise TFS Nov 19, 2018 at 16:36
10

Assuming you administer a private NuGetGallery server and have access to the MSSQL Server database, you can remove the package by removing the gallery's knowledge of its existence.

You should probably never use this, but in the interests of science, here's how you would disregard the good reasons not to (note that this will delete all versions of a package called 'MyNastyPackage'):

DECLARE @PackageRegistrationKey int
SELECT @PackageRegistrationKey = [Key]
 FROM PackageRegistrations
 WHERE Id = 'MyNastyPackage'

BEGIN TRANSACTION
DELETE pf
 FROM [NuGetGallery].[dbo].[PackageFrameworks] pf
 JOIN Packages p ON pf.Package_Key = p.[Key]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE pa
 FROM [NuGetGallery].[dbo].[PackageAuthors] pa
 JOIN Packages p ON pa.PackageKey = p.[Key]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE gs
 FROM [NuGetGallery].[dbo].[GallerySettings] gs
 JOIN [PackageStatistics] ps ON gs.DownloadStatsLastAggregatedId = ps.[Key]
 JOIN Packages p ON ps.PackageKey = p.[Key]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE ps
 FROM [NuGetGallery].[dbo].[PackageStatistics] ps
 JOIN Packages p ON ps.PackageKey = p.[Key]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE pd
 FROM [NuGetGallery].[dbo].[PackageDependencies] pd
 JOIN Packages p ON pd.PackageKey = p.[Key]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE
 FROM [NuGetGallery].[dbo].[Packages]
 WHERE PackageRegistrationKey = @PackageRegistrationKey
DELETE por
 FROM PackageOwnerRequests por
 JOIN PackageRegistrations pr ON pr.[Key] = por.PackageRegistrationKey
 WHERE pr.[Key] = @PackageRegistrationKey
DELETE pro
 FROM PackageRegistrationOwners pro
 JOIN PackageRegistrations pr ON pr.[Key] = pro.PackageRegistrationKey
 WHERE pr.[Key] = @PackageRegistrationKey
DELETE FROM PackageRegistrations
 WHERE [Key] = @PackageRegistrationKey
COMMIT TRANSACTION
1
5

Then you got an email from NuGet when you succeed to publish it.

Put an eye on this email because there they wrote:

If this was not intended, please "contact support".

if you click on "contact support", this is linked to your package manage in NuGet and where you can give a reson why you want to delete it and then give the action to delete it.

That's all!

1

If you click Delete Package in the package's sub menu (on the left), you are redirected to another page telling you this:

If you need the package permanently removed, click on the Contact Support link and we'll take care of it for you

As for me this worked totally fine, I contacted the support requesting my package to be removed because I accidently uploaded it on the productive NuGet server instead of the staging environment.

However, I would always recommend testing your package first using staging.nuget.com. You can then add the staging environment as package repository in Visual Studio for testing.

0

Well, in your particular case you can add a dependency by manually editing .nuspec file if you have an access to your nuget server. Open the data directory of the nuget server (where it stores its .nupkg files), find the package and either use NugetPackageExplorer tool or edit the metadata manually (.nupkg file is a zip archive, open it and edit YourPackageName.nuspec file to add a dependency). It would look like similar to this:

<dependencies>
  <dependency id="RouteMagic" version="1.1.0" />
  <dependency id="RouteDebugger" version="1.0.0" />
</dependencies>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.