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?
Running the following from Package Manager Console within Visual Studio gives me the required information:
Get-Project | Get-Package | select Id, Version, LicenseUrl
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.
go to the Project or Solution in question. right click, Manage NuGet Packages... on the left, you will see 'Installed Packages' click on this and you will see the list.
Fortunately, many NuGet packages use the exact same license agreement. This means that, if you can get approval for one type of license (ex. "MIT License Agreement"), then all other packages with that license would be acceptable.
nuspec file is an XML manifest that contains package metadata. This manifest is used both to build the package and to provide information to consumers. The manifest is always included in a package. In this topic: General form and schema.
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)
And here is how resources\tools\PreBuildScript.ps1
looks like:
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"
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With