Sabby62
Sabby62

Reputation: 1717

Get licenses for the Nuget Packages in VS2015

Is there a way I can download Nuget Packages license ? I know this has been questioned/answered but I want something to work with VS2015 Update 2. Having a powershell script that checks my projects and then creates the .txt file either having package name with the license url.

Upvotes: 1

Views: 1684

Answers (2)

peterr
peterr

Reputation: 111

I've managed to get the list of licenses with Visual Studio 2015 Update 2 with this:

Split-Path -parent $dte.Solution.FileName | cd; New-Item -ItemType Directory -Force -Path ".\licenses"; @( Get-Project -All | ? { $_.ProjectName } | % { Get-Package -ProjectName $_.ProjectName | ? { $_.LicenseUrl } } ) | Sort-Object Id -Unique | % { $pkg = $_; Try { if ($_.Id -notlike 'microsoft*' -and $_.LicenseUrl.StartsWith('http')) { Write-Host ("Download license for package" + $pkg.Id + " from " + $pkg.LicenseUrl); (New-Object System.Net.WebClient).DownloadFile($_.LicenseUrl, (Join-Path (pwd) 'licenses\') + $_.Id + ".html"); } } Catch [system.exception] { Write-Host ("Could not download license for" + $pkg.Id) }  }

You will probably need to modify the download path, currently it creates the licenses subfolder in the solution folder and downloads there. Also it filters out all Microsoft packages, but if you need them it's easy to modify the code.

This code is based on the code from this post. And I'm sure it can be improved, because I'm not that much at home with powershell.

Upvotes: 4

Matt Ward
Matt Ward

Reputation: 47987

The license url is not currently available from PowerShell with NuGet 3.

It has being added to NuGet 3.4.

The simple PowerShell script in this other StackOverflow answer works with NuGet 3.4.

If you are using an older version of NuGet 3 that leaves you with writing some code that looks at the .nuspec file inside the NuGet package (.nupkg) and reads the license url from there.

Upvotes: 0

Related Questions