delist-nuget.ps1 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. $apiKey = "" # Replace with your actual API key
  2. # Unlist all packages matching "2.0.0-v2-develop.*"
  3. # PowerShell script to unlist NuGet packages using dotnet CLI
  4. $packageId = "terminal.gui" # Ensure this is the correct package name (case-sensitive)
  5. $packagePattern = "^2\.0\.0-develop\..*$" # Regex pattern for filtering versions
  6. $nugetSource = "https://api.nuget.org/v3/index.json"
  7. # Fetch package versions from NuGet API
  8. $nugetApiUrl = "https://api.nuget.org/v3-flatcontainer/$packageId/index.json"
  9. Write-Host "Fetching package versions for '$packageId'..."
  10. try {
  11. $versionsResponse = Invoke-RestMethod -Uri $nugetApiUrl
  12. $matchingVersions = $versionsResponse.versions | Where-Object { $_ -match $packagePattern }
  13. } catch {
  14. Write-Host "Error fetching package versions: $_"
  15. exit 1
  16. }
  17. if ($matchingVersions.Count -eq 0) {
  18. Write-Host "No matching packages found for '$packageId' with pattern '$packagePattern'."
  19. exit 0
  20. }
  21. # Unlist each matching package version
  22. foreach ($version in $matchingVersions) {
  23. Write-Host "Unlisting package: $packageId - $version"
  24. dotnet nuget delete $packageId $version --source $nugetSource --api-key $apiKey --non-interactive
  25. }
  26. Write-Host "Operation complete."