How to remove a package from

I wanted to remove/unlist one of my packages from 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("");
    var packages = from package in repo.FindPackagesById(packageID)
        where package.IsListed()
        select package;
    return packages;

The problem is that the “Nuget.Core” library to 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.");