Skip to content

Instantly share code, notes, and snippets.

@tjrobinson
Created August 2, 2013 08:45
Show Gist options
  • Save tjrobinson/6138411 to your computer and use it in GitHub Desktop.
Save tjrobinson/6138411 to your computer and use it in GitHub Desktop.
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