自动创建nuget软件包和许可证列表 [英] Automatically create list of nuget packages and licenses

查看:239
本文介绍了自动创建nuget软件包和许可证列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there any way to get an automatically updated list of all used nuget packages in my solution, including a link to the corresponding license, which I can display within my app?

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

Running the following from Package Manager Console within Visual Studio gives me the required information:

Get-Project | Get-Package | select Id, Version, LicenseUrl 

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

How to get this list a) automatically updated on each change and b) get it into my app?

目标是要有一个显示所有这些数据的信息/关于"对话框.

Target is to have an Info/About dialog showing all this data.

推荐答案

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

I found one way, pretty sure it has some limitations...

我在构建前事件中称呼它为

I'm calling this in the pre-build event:

powershell.exe -ExecutionPolicy Bypass -File $(ProjectDir)\Resources\tools\PreBuildScript.ps1  $(ProjectDir) $(SolutionDir) $(TargetDir)

这是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"

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

This gives me an (ugly) textfile Resources\ThirdPartyLicenseOverview.txt that I can include as embedded resource to use it within my app.

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

Not the final solution but one step on the way...

这篇关于自动创建nuget软件包和许可证列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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