-
-
Save asbjornu/b31ca996a40a54f18bca01fff0335608 to your computer and use it in GitHub Desktop.
Unlist all versions of a NuGet package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$PackageId = "xxx" | |
$ApiKey = "yyy" | |
$json = Invoke-WebRequest -Uri "https://api.nuget.org/v3-flatcontainer/$PackageId/index.json" | ConvertFrom-Json | |
foreach ($version in $json.versions) | |
{ | |
Write-Host "Unlisting $PackageId, Ver $version" | |
Invoke-Expression "dotnet nuget delete $PackageId $version --non-interactive --api-key $ApiKey --source https://api.nuget.org/v3/index.json" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit #abort if any command fails | |
[ "${DEBUG:-false}" = "true" ] && set -x | |
me=$(basename "$0") | |
help_message="\ | |
Usage: $me <package-id> <api-key> | |
Deletes (unlists) the <package-id> from nuget.org. | |
Arguments: | |
package-id The ID of the package you want to delete. | |
api-key The nuget.org API key with access to delete the package." | |
package_id="$1" | |
api_key="$2" | |
if [[ -z "$package_id" ]]; then | |
echo "Missing argument: package-id. Aborting." >&2 | |
echo "$help_message" >&2 | |
exit 1 | |
fi | |
if [[ -z "$api_key" ]]; then | |
echo "Missing argument: api-key. Aborting." >&2 | |
echo "$help_message" >&2 | |
exit 1 | |
fi | |
json=$(wget --quiet --output-document - "https://api.nuget.org/v3-flatcontainer/$package_id/index.json" 2> /dev/null) | |
count=$(echo "$json" | jq -r '.versions | length') | |
versions=$(echo "$json" | jq -r '.versions[]') | |
echo "Unlisting $count versions of $package_id..." | |
echo "" | |
for version in $versions; do | |
echo "Unlisting $package_id, version $version." | |
dotnet nuget delete "$package_id" "$version" --non-interactive --api-key "$api_key" --source "https://api.nuget.org/v3/index.json" | |
echo "" | |
# Sleep for 5 seconds to avoid exceeding NuGet's rate limits: | |
# https://docs.microsoft.com/nb-no/nuget/api/rate-limits#package-push-and-unlist | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment