Ever wanted to get metadata from your NuGet packages, such as author or license information? Ever wanted to get metadata from your NuGet packages, such as author or license information? Got lost looking for it in Visual Studio? Are you looking for a simple script that is able to output all metadata information from a single command? Look no further!
This cmdlet is easy to use and simple to integrate with your build / continuous integration process. If you don't have any previous experience with scripting or PowerShell, follow the examples below.
Open powershell and run
$ Install-Module NuGetMetadata
This cmdlet is publicly distributed through PowerShell gallery. To install, simply open a powershell window (run as administrator) and run the following:
PS> Install-Module NuGetMetadata
Open a PowerShell prompt in your project directory and run:
PS> Get-NuGetMetadata
It will output the metadata contents of every NuGet package within the project. It does this by searching for .nupkg files in the folder you're in, open them, and output the contents of the .nuspec files it finds.
You can provide both folders and files:
PS> Get-NuGetMetadata C:\Project\
PS> Get-NuGetMetadata .\example.nupkg
Or a combination of both:
PS> Get-NuGetMetadata .\example.nupkg, C:\Project\
With powershell it's easy to save the data to file.
PS> Get-NuGetMetadata | Export-Csv -NoTypeInformation ./my-metadata-file.csv
This produces a file named my-metadata-file.csv in the directory you are in.
Since the Get-NugetMetadata cmdlet produces xml objects, it can't be easily converted to Json using ConvertTo-Json. One workaround is to pipe via select, which then creates a PSObject that can be converted:
PS> Get-NuGetMetadata | Select-Object id, version, licenseUrl | ConvertTo-Json | Out-File ./my-metadata-file.csv
To exclude, for example, Microsoft packages:
PS> Get-NuGetMetadata | ? { $_.id -notlike 'Microsoft*' }
This is just a simple example. One caveat is that it doesn't clean the output folder on each invocation.
In your project directory, create a folder called "Licenses".
PS> mkdir Licenses
The line below downloads the license url contents, and saves them as separate html files (named after the identifier).
PS> Get-NuGetMetadata | select id, licenseUrl | % { (Invoke-WebRequest $_.licenseUrl).Content |
Out-File -FilePath "./Licenses/$($_.id).html" }
- 1.0.0
- Released and published on PowerShell Gallery
Distributed under the MIT license. See LICENSE
for more information.