Finding third party licenses with Nuget

不羁岁月 提交于 2019-11-30 02:08:21

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")
}
burly bogdan

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"
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!