Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find NuGet packages across multiple solutions
$packagesInUse = @()
[xml] $nugetConfig = [xml](Get-Content nuget.config)
[System.Xml.XmlElement] $nugetConfigRoot = $nugetConfig.get_DocumentElement()
$repositoryPath = $nugetConfigRoot.SelectSingleNode("repositoryPath").InnerText
Write-Host "repositoryPath:" $repositoryPath
[xml] $repositories = [xml](Get-Content $repositoryPath\repositories.config)
[System.Xml.XmlElement] $repositoriesRoot = $repositories.get_DocumentElement()
$packageConfigs = $repositoriesRoot.SelectNodes("repository")
foreach($packageConfig in $packageConfigs)
{
$packagesConfigPath = $packageConfig.Attributes["path"].Value
[xml] $packagesConfig = [xml](Get-Content $repositoryPath\$packagesConfigPath)
[System.Xml.XmlElement] $packagesConfigRoot = $packagesConfig.get_DocumentElement()
$packages = $packagesConfigRoot.SelectNodes("package")
foreach($package in $packages)
{
$packagesInUse = $packagesInUse + [string] ($package.Attributes["id"].Value + ", " + $package.Attributes["version"].Value + ", " + $packagesConfigPath.Replace("\packages.config","").Replace("..\",""))
}
}
foreach($packageInUse in $packagesInUse | Sort-Object)
{
Write-Host $packageInUse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment