简体   繁体   English

在VS2015中获取Nuget软件包的许可证

[英]Get licenses for the Nuget Packages in VS2015

Is there a way I can download Nuget Packages license ? 有什么方法可以下载Nuget软件包许可证? 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. 我知道这已经受到质疑/回答,但我希望可以在VS2015 Update 2中使用。有一个Powershell脚本来检查我的项目,然后创建.txt文件,其文件名带有许可证URL。

I've managed to get the list of licenses with Visual Studio 2015 Update 2 with this: 我已经设法通过Visual Studio 2015 Update 2获得了许可证列表:

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. 您可能需要修改下载路径,当前它会在解决方案文件夹中创建licenses子文件夹并在此处下载。 Also it filters out all Microsoft packages, but if you need them it's easy to modify the code. 它还过滤掉所有Microsoft软件包,但是如果您需要它们,可以轻松修改代码。

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. 而且我确信它可以改进,因为我对Powershell的了解并不多。

The license url is not currently available from PowerShell with NuGet 3. 使用NuGet 3,PowerShell当前不提供许可证URL。

It has being added to NuGet 3.4 . 它已添加到NuGet 3.4中

The simple PowerShell script in this other StackOverflow answer works with NuGet 3.4. 其他StackOverflow答案中的简单PowerShell脚本可与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. 如果您使用的是较旧版本的NuGet 3,则可以编写一些代码,这些代码将查看NuGet软件包(.nupkg)中的.nuspec文件,并从那里读取许可证URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM