3
votes

I have a package in a private package feed of my Visual Studio Team Services (VSTS) account and want to unlist all versions of my package since it's deprecated and has been superseded by a different package.Thus I want to mark the old package as deprected by unlisting it (not deleting it, if possible)

Unfortunately all I can find is a button that unlists one specific version of the package, like described here. Removing my legacy package that way takes ages since I have to unlist easily 30 versions before the package is removed from my feed.

I know that nuget.org has the functionality to unlist all versions of a package with just one click and I'd consider it to be a basic function. Does anyone know whether there's a trick or hidden button that allows me to unlist packages more easily in VSTS? Or is there maybe a nuget cli command for that?

6

6 Answers

5
votes

No matter by VSTS web UI or nuget cli, the packages can only be unlisted one by one.

The format for unlist a package as:

nuget delete <packageID> <packageVersion> [options]

But you can write your own script to unlist packages in your VSTS feed in loop. Detail steps as:

1. Add the VSTS feed as source with credential

nuget sources add -Name "feedname" -Source "https://account.pkgs.visualstudio.com/_packaging/feedname/nuget/v3/index.json" -Username <Alternate username/email> -password <Alternate password/PAT>

2. List all the packages in the VSTS feed

nuget list -source feedname -AllVersions

3. Loop the packages you get in step2, and unlist them in the loop

nuget delete packagename packageversion -source feedname -ApiKey key
2
votes

The TFS Packages UI allows you to multi select and unlist using CTRL or SHIFT type selects. I use that to unlist and promote packages.

2
votes

no script needed to unlist all packages.

it can be done in few clicks in UI:

  1. go to your Devops UI
  2. open the nuget repository
  3. then go to Artifacts/Packages
  4. select the your package
  5. open Versions tab
  6. tick the first record in the list (so you will see a round tick next to it)
  7. scroll down to the end of the list and tick the last record while you holding Shift key
  8. select Unlist at the top menu

IMPORTANT NOTE: at the moment of writing there is a bug in Devops UI: if you select more than 100 records, Unlist command does not do anything. So you may need to select records in batches of 100 records (or less) to make it work!

1
votes

I've created and used the following powershell script to unlist all nuget packages from my tfs feed.

$nugetFeed = "http://tfs/MyTeam/_packaging/MyProject/nuget/v3/index.json"
$nugetExe = "C:\pathToNuget\nuget.exe"
$packageToDelete = "MyPackage"
$apiKey = "VSTS"

function Get-PackageVersions
{
    Param
    (
        [string]$Package,
        [string]$Feed,
        [string]$Nuget
    )

    $packageContent = & $Nuget list -Source $Feed -PreRelease -AllVersions
    $packages = $packageContent.Split([Environment]::NewLine)
    foreach($line in $packages) {
        $parts = $line.Split(' ')
        $packageName = $parts[0]
        $packageVersion = $parts[1]
        if($packageName -eq $Package) {
            $packageVersion
        }
    }
}

$versions = Get-PackageVersions -Package $packageToDelete -Feed $nugetFeed -Nuget $nugetExe
foreach($version in $versions) {
    & $nugetExe delete $packageToDelete $version -Source $nugetFeed -ApiKey VSTS $apiKey
}
1
votes

If you need the same thing for nuget, and came here from google you can also use this:

dotnet tool install --global NugetUnlister

and then

nuget-unlist drop PrereleaseBefore -p Some.Package --sv [0.1.3] -k somekey 
0
votes

For whoever wants to do it via the DevOps UI. I wrote that little console script that marks up to 100 versions (limit by UI) which you then can unlist. If you increase the scroll counter you wont need to start always over again ;)

it does scroll down automatically und waits for the entries to load.

(() => { let view = document.getElementsByClassName('vss-PivotBar--content')[0]; let scroll = 0; let markedElements = 0; let doit = () => { if(view.scrollTop + 500 < view.scrollHeight && markedElements < 100) { console.log('i did scroll to: ' + scroll); let list = document.getElementsByClassName('ms-List-cell'); for (var el of list) { if(el.getElementsByClassName('strike-through').length == 0) { let btn = el.getElementsByClassName('ms-Check')[0]; if(btn.className.indexOf('is-checked') == -1 && markedElements < 100) {btn.click(); markedElements++;} } }console.log(markedElements); scroll++; view.scrollTo(0, 500 * scroll); setTimeout(()=>doit(), 2000); }}; doit(); })()