Over a million developers have joined DZone.

How to Remove a Package From NuGet.org

Need to remove a package from NuGet.org? Read on to find out how to do this in this helpful post.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

I wanted to remove/unlist one of my packages from nuget.org. It was however not a trivial task to perform as ALL package versions must be unlisted. This article will show you a programmatic way to do so.

Start by creating a new console application in Visual Studio and install the NuGet package “NuGet.Core”. With that package, you can download a list of all package versions of your package.
The code for that method should look something like this:

private static IEnumerable<IPackage> GetListedPackages(string packageID)
    var repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
    var packages = from package in repo.FindPackagesById(packageID)
        where package.IsListed()
        select package;
    return packages;

The problem is that the “NuGet.Core” library does not support the remove action. So you can get a nice list of all versions that have to be removed. But you can’t remove them.

My approach was to copy nuget.exe from the “.nuget” folder in one of my projects and include it in the console application:

unlist all project

Once that is done it’s rather trivial. Set “Copy to Output Directory” to “Copy if newer” in the file properties.

Now we can run the “nuget remove” command from our code:

private static string UnlistPackage(IPackage package, string apiKey)
    var arguments = $"delete {package.Id} {package.Version} -ApiKey {apiKey} -NonInteractive";
    var psi = new ProcessStartInfo("nuget.exe", arguments)
        RedirectStandardOutput = true,
        WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
        UseShellExecute = false
    var process = Process.Start(psi);
    return process.StandardOutput.ReadToEnd();

Notice that I copy the output from the command to verify that it was actually run.

The last thing that we need is the code that ties everything together:

private static void Main(string[] args)
    var packageID = "yourPackageName";
    var apiKey = "yourKeyFromNugetOrg";

    var packages = GetListedPackages(packageID);

    foreach (var package in packages)
        Console.WriteLine("Unlisting package " + package);
        var output = UnlistPackage(package, apiKey);

    Console.Write("Completed. Press ENTER to quit.");

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

repo,packages,nuget,remove,example,tips,c#,visual studio

Published at DZone with permission of Jonas Gauffin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}