Friday, June 05, 2020

Quick tip: exporting all nuget packages used in Visual Studio solution to text file with PowerShell

Although it is possible to manage Nuget packages at solution level in Visual Studio with the possibility to even consolidate the Nuget packages it might be useful as well to have an overview of all of the packages that you use in another format. 



The below PowerShell code snippet allows you to export all used Nuget packages to a text file (you can ignore the exceptions thrown because of  projects without Nuget packages).

Get-Content .\[yoursolutionname].sln 
| where { $_ -match "Project.+, ""(.+)\\([^\\]+).csproj"", " }
| foreach { "$($matches[1])\packages.config" } | % { Get-Content $_ | Find "<package id" } | Sort-Object -Unique | Out-File -FilePath c:\temp\packages_demo


No comments: