如何使用 nuget.exe 命令行获取特定 Visual Studio 解决方案的包列表 [英] How to get list of packages of a particular Visual Studio solution with nuget.exe command line

查看:10
本文介绍了如何使用 nuget.exe 命令行获取特定 Visual Studio 解决方案的包列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行 nuget restore 命令后获取我的 Visual Studio 解决方案的包列表.如何从命令行或 Powershell (oustide Visual Studio) 执行此操作?

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

推荐答案

您可以运行以下 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")

这篇关于如何使用 nuget.exe 命令行获取特定 Visual Studio 解决方案的包列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆