自动创建nuget软件包和许可证列表

sc9*_*911 5 visual-studio nuget

有什么方法可以获取解决方案中所有已使用的nuget软件包的自动更新列表,包括指向可以在我的应用程序中显示的相应许可证的链接?

从Visual Studio的Package Manager控制台中运行以下命令可为我提供所需的信息:

Get-Project | Get-Package | select Id, Version, LicenseUrl 
Run Code Online (Sandbox Code Playgroud)

如何获取此列表a)在每次更改时自动更新,以及b)将其添加到我的应用中?

目标是显示所有这些数据的“信息/关于”对话框。

sc9*_*911 3

我找到了一种方法,很确定它有一些限制......

我在预构建事件中调用它:

powershell.exe -ExecutionPolicy Bypass -File $(ProjectDir)\Resources\tools\PreBuildScript.ps1  $(ProjectDir) $(SolutionDir) $(TargetDir)
Run Code Online (Sandbox Code Playgroud)

看起来是这样resources\tools\PreBuildScript.ps1的:

param (
    [Parameter(Mandatory=$True)]
    [string]$ProjectDir,
    [Parameter(Mandatory=$True)]
    [string]$SolutionDir,
    [Parameter(Mandatory=$True)]
    [string]$TargetDir
)
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
$nupkgs = Get-ChildItem -Recurse -Filter *.nupkg -Path "$SolutionDir\packages" 
$nuspecs = $nupkgs | %{ [IO.Compression.ZipFile]::OpenRead($_.FullName).Entries | where {$_.Fullname.EndsWith('.nuspec')} } 
$metadata = $nuspecs | %{ 
    ([xml]([System.IO.StreamReader]$_.Open()).ReadToEnd()) | %{New-Object PSObject -Property @{
        Version = $_.package.metadata.version
        Authors = $_.package.metadata.authors 
        Title =  IF ([string]::IsNullOrWhitespace($_.package.metadata.title)){$_.package.metadata.id} else {$_.package.metadata.title}
        LicenseUrl  = $_.package.metadata.licenseUrl
    }}
} 
$metadata | %{ '{0} {1}{4}Autor(en): {2}{4}Lizenz: {3}{4}{4}' -f $_.Title, $_.Version, $_.Authors, $_.LicenseUrl, [Environment]::NewLine } | Out-File "$ProjectDir\Resources\ThirdPartyLicenseOverview.txt"
Run Code Online (Sandbox Code Playgroud)

这给了我一个(丑陋的)文本文件Resources\ThirdPartyLicenseOverview.txt,我可以将其作为嵌入式资源包含在我的应用程序中使用它。

不是最终的解决方案,而是前进的一步......