Skip to content

Instantly share code, notes, and snippets.

@richardnagle
Created July 14, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardnagle/2ffa63c3a9a711aa97c929192d8cbcef to your computer and use it in GitHub Desktop.
Save richardnagle/2ffa63c3a9a711aa97c929192d8cbcef to your computer and use it in GitHub Desktop.
Powershell script for updating nuget packages
Param(
[string]$nugetTarget,
[string]$nugetUrl
)
Write-Host "Getting installed packages from packages.configs"
$installedPackages = Get-ChildItem -path '.' -Recurse -Include 'packages.config' |
Select-Xml -xpath '//package/@id' |
Select-Object -ExpandProperty Node |
Select-Object -ExpandProperty value |
Sort-Object -Unique
Write-Host "Getting available update from $nugetUrl"
$availablePackages = nuget list -source $nugetUrl |
foreach {$_.Split(' ')[0]}
Write-Host "Updating NuGetPackages"
$nugetExeIdArgs = @()
$installedPackages |
where {$availablePackages -contains $_} |
ForEach-Object {
Write-Host("Updating $_")
$nugetExeIdArgs += "-Id"
$nugetExeIdArgs += $_
}
$nuget = 'nuget.exe'
$arguments = "update", $nugetTarget, "-Source", $nugetUrl, "-Source", "https://api.nuget.org/v3/index.json"
$arguments += $nugetExeIdArgs
&$nuget $arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment