Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
Forked from rjmurillo/pack-man.ps1
Last active July 31, 2020 14:04
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 ChrisMcKee/daf6622bbd9eda49fc13e36e43ffc519 to your computer and use it in GitHub Desktop.
Save ChrisMcKee/daf6622bbd9eda49fc13e36e43ffc519 to your computer and use it in GitHub Desktop.
Useful Package Manager console commands
Get-Project –All | Add-BindingRedirect
# On large projects commands like `Update-Package -Reinstall` can take HOURS
# If the updates are broken up, then don't lock up the IDE and complete much faster (minutes vs hours)
# Reinstall all packages that match a specific targetFramework
# Useful when retargeting
gci -recurse packages.config | % { [xml]$XmlDocument = Get-Content -Path $_.FullName; $XmlDocument.packages.package | ? { $_.targetFramework -eq 'net462' } | select id | sort-object -unique | % { update-package -reinstall $_.id } }
# Reinstall all packages that have been marked with requireReinstallation
gci -recurse packages.config | % { [xml]$XmlDocument = Get-Content -Path $_.FullName; $XmlDocument.packages.package | ? { $_.requireReinstallation -eq 'true' } | select id | sort-object -unique | % { update-package -reinstall $_.id } }
# Reinstall packages for test projects only
# Uses naming convention to identify test projects
Get-Project -All | where { $_.ProjectName.EndsWith(".Tests") } | % { Update-Package -Reinstall -Project $_.ProjectName }
ForEach($project in get-project -all) { ForEach($package in Get-Package -ProjectName $project.ProjectName | ?{ $_.Id -like 'System.*'}) { Uninstall-Package -ProjectName $project.ProjectName -Id $package.Id -Force;} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment