如何在PowerShell中获取NuGet包作者?

问题描述 投票:1回答:1

我想获得一个NuGet包信息。我已经有脚本,像这样:

@( Get-Project -All | ? { $_.ProjectName } | %  {
Get-Package -ProjectName $_.ProjectName } ) | ? { $_.LicenseUrl } | % {
$pkg  = $_ ;

$ pkg.Id是可访问的$ pkg.LicenseUrl是可访问的

但我无法理解当我打印$ pkg时,输出包含Id,Versions,ProjectName。如何访问LicenseUrl。

$ pkg.Authors无法访问。我不能用任何从NugetPackages获取自己的脚本。请帮助我。

powershell nuget package nuget-package
1个回答
0
投票

你可以查询NuGet API

function Get-PackageAuthors {
    param (
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
            ValueFromPipelineByPropertyName = $true
        )]
        [string]$Id
    )
    process {
        $url = "https://api-v2v3search-0.nuget.org/query?q=$Id&take=1"
        $response = Invoke-RestMethod $url
        if ($response.totalHits -gt 0) {
            return $response.data.authors
        }
    }
}

# usage:
Get-Package | Get-PackageAuthors
© www.soinside.com 2019 - 2024. All rights reserved.