【问题标题】:How to get list of packages of a particular Visual Studio solution with nuget.exe command line如何使用 nuget.exe 命令行获取特定 Visual Studio 解决方案的包列表
【发布时间】:2017-05-18 23:45:47
【问题描述】:

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

【问题讨论】:

    标签: visual-studio powershell nuget


    【解决方案1】:

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

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

    【讨论】:

    • 有效!非常感谢 :) 虽然遗憾的是,此功能无法通过 nuget.exe 或 powershell cmdlet 开箱即用。
    • 我只需要过滤掉重复的条目,我只对每个单独的包感兴趣,而不管它属于哪个 packages.config 文件。
    猜你喜欢
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 2012-01-03
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 1970-01-01
    相关资源
    最近更新 更多