简体   繁体   中英

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)?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM