且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 nuget.exe 命令行获取特定 Visual Studio 解决方案的包列表

更新时间:2023-10-05 12:47:52

您可以运行以下 PowerShell 脚本来列出解决方案中所有已安装的包.请修改 $SOLUTIONROOT 作为您的解决方案路径.

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 ProjectSO Case SamplePackageSource"

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