Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding third party licenses with Nuget

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.

like image 477
Klee Avatar asked Apr 05 '12 02:04

Klee


People also ask

Where can I find NuGet package source?

To manage your package sources, select the Settings icon or select Tools > Options. In the Options window, expand the NuGet Package Manager node and select Package Sources.

How use NuGet command line?

To use any command, open a command window or bash shell, then run nuget followed by the command and appropriate options, such as nuget help pack (to view help on the pack command). This documentation reflects the latest version of the NuGet CLI.

What command can you use to search for a package in the NuGet Package Manager console?

Quickly find and install a package Open your project or solution in Visual Studio, and select Tools > NuGet Package Manager > Package Manager Console to open the Package Manager Console window. In the console, enter Find-Package with a keyword to find the package you want to install.

How do you check if I have NuGet?

In Visual Studio, use the Help > About Microsoft Visual Studio command and look at the version displayed next to NuGet Package Manager. Alternatively, launch the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console) and enter $host to see information about NuGet including the version.


1 Answers

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")
}
like image 104
Matt Ward Avatar answered Oct 08 '22 03:10

Matt Ward