Agustin Berbegall
Agustin Berbegall

Reputation: 85

How to get list of packages of a particular Visual Studio solution with nuget.exe command line

I would like to get a list of packages of my Visual Studio solution after I ran the nuget restore command. How can I do it from command line or Powershell (oustide Visual Studio)?

Upvotes: 3

Views: 3982

Answers (1)

Weiwei
Weiwei

Reputation: 3776

You could run following PowerShell script to list all installed packages in your solution. Please modify the $SOLUTIONROOT as your solution path.

#This will be the root folder of all your solutions - we will search all  children of this folder
$SOLUTIONROOT = "D:\Visual Studio 2015 Project\SO Case Sample\PackageSource"

Function ListAllPackages ($BaseDirectory)
{
    Write-Host "Starting Package List - This may take a few minutes ..."
    $PACKAGECONFIGS = Get-ChildItem -Recurse -Force $BaseDirectory -ErrorAction SilentlyContinue | 
        Where-Object { ($_.PSIsContainer -eq $false) -and  ( $_.Name -eq "packages.config")}
    ForEach($PACKAGECONFIG in $PACKAGECONFIGS)
        {
            $path = $PACKAGECONFIG.FullName
            $xml = [xml]$packages = Get-Content $path
                            foreach($package in $packages.packages.package)
                            {
                                 Write-Host $package.id
                             }

        }
}

ListAllPackages $SOLUTIONROOT
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Upvotes: 6

Related Questions