Finding third party licenses with Nuget

Go To StackoverFlow.com

11

I'm a bit of a NuGet newbie and have come from the Maven world.

Recently I've been tasked with updating the third party licence information for our projects. Working with the Maven projects I've been able to use the license:download-licenses plugin to get the licence information.

What I'm wondering is if there is a way to get this information using Nuget? Preferably by using the command line interface so I can automate it at a CI build level. To remove it from the large manual pre build step.

EDIT:

Since I wasn't able to find any utilities to do this I put together the LegSec command line utility.

2012-04-05 02:44
by Klee
Thank you for posting the link to your project! I used LegSec today... the command-line usage was a little difficult to figure out (some trial+error), but the functionality was great - crimbo 2014-04-18 22:15
Apparently they know how to do it since 2013, it's just never been exposed programmatically: https://blog.nuget.org/20131011/friendly-license-names.html. I opened an issue you might want to upvote: https://github.com/NuGet/Home/issues/5793 - Ohad Schneider 2017-08-23 09:15


11

As far as I am aware there is nothing currently available to get the license information directly from the command line as part of a CI build. You would need to create an application to open the .nupkg zip file, extract the license url from the .nuspec file and download the license from this url.

Alternatively you could use the package manager console window inside Visual Studio and with a bit of PowerShell download the license files.

A simple example that gets the license file for all packages in a project is shown below. This would need to be extended to get all the projects in the solution which you should be able to do with the Get-Project cmdlet. This would still require someone to run the script to download the licenses.

$wc = New-Object System.Net.WebClient
Get-Package -ProjectName YourProject | ForEach-Object {
    $wc.DownloadFile($_.LicenseUrl, 'd:\licenses\' + $_.Id + ".html")
}
2012-04-07 15:06
by Matt Ward
Just a note - In VS2015 'LicenseUrl' always returns an empty string. NuGet documentation says 'LicenseUrl' will be deprecated from v3.x on wards, buts does not mention about any alternative - James Poulose 2015-11-20 05:33
The LicenseUrl has been added back in NuGet 3.4 or above - Matt Ward 2016-05-06 08:57


0

I managed to get the licence information with the following command:

@(@(Get-Project -All | ForEach-Object {
    Get-Package -ProjectName $.ProjectName
}) | Select Id -Unique ) | ForEach-Object {
    $pkg = $_
    $pkgId = $_.Id
    if ($pkgId -notlike 'microsoft*') {
        $url = Open-PackagePage $pkgId -License -WhatIf -PassThru
        Write-Host "$pkgId $url"
    }
}
2015-09-30 16:02
by burly bogdan
Ads