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

How to get NuGet package authors in PowerShell?

我想获取 NuGet 包信息。我已经编写了脚本,如下所示:

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

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

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

$pkg.Authors 不可访问。我无法从 NugetPackages 获取 autohers 的任何脚本。请帮助我。

您可以查询 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