Last active
September 29, 2018 00:24
-
-
Save ashmind/26212d1adea1de2bdeed to your computer and use it in GitHub Desktop.
Save to your NuGet Profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For each package, lists which projects it is installed in | |
function Write-PackageProjectInstalls([string] $PackageFilter = '') { | |
Set-StrictMode -Version 2 | |
$ErrorActionPreference = 'Stop' | |
Get-Project -All | | |
% { | |
$ProjectName = $_.ProjectName | |
Get-Package $PackageFilter -Project $ProjectName | | |
% { New-Object PSObject -Prop (@{ ProjectName=$ProjectName; PackageId=$_.Id; Version = $_.Version; }) } | |
} | | |
group -Property PackageId | | |
sort Name | | |
% { | |
Write-Host $_.Name | |
$_.Group | | |
group -Property Version | | |
sort Name | % { | |
Write-Host " $($_.Name)" | |
$_.Group | | |
sort ProjectName | | |
% { Write-Host " $($_.ProjectName)" } | |
} | |
} | |
} | |
# Basically Update-Package -Force | |
function Update-PackageByForcedReinstall([Parameter(Mandatory=$true)] [string] $Id, [string] $Version) { | |
Set-StrictMode -Version 2 | |
$ErrorActionPreference = 'Stop' | |
Get-Project -All | | |
% { $_.ProjectName } | | |
? { Get-Package $Id -Project $_ | ? { $_.Id -ieq $Id } } | | |
% { | |
Uninstall-Package $Id -Force -Project $_ | |
Install-Package $Id -Project $_ -Version $Version | |
} | |
} | |
# So that you can install same version as is already installed in other projects, | |
# e.g. by doing Install-Package X -Version (Get-PackageLatestInstalledVersion X) | |
function Get-PackageLatestInstalledVersion([Parameter(Mandatory=$true)] [string] $Id) { | |
Set-StrictMode -Version 2 | |
$ErrorActionPreference = 'Stop' | |
Get-Project -All | | |
% { $_.ProjectName } | | |
% { Get-Package $Id -Project $_ } | | |
? { $_.Id -ieq $Id } | | |
% { $_.Version } | | |
sort -Descending | | |
select -First 1 | |
} | |
# Unistalls package from all projects | |
function Unistall-PackageFromAllProjects([Parameter(Mandatory=$true)] [string] $Id) { | |
Set-StrictMode -Version 2 | |
$ErrorActionPreference = 'Stop' | |
Get-Project -All | | |
% { $_.ProjectName } | | |
? { Get-Package $Id -Project $_ | ? { $_.Id -ieq $Id } } | | |
% { Uninstall-Package $Id -Force -Project $_ } | |
} | |
# Update all packages that match a wildcard (e.g. Microsoft.AspNet.*) | |
function Update-PackageByWildcard([Parameter(Mandatory=$true)] [string] $IdFilter, [switch] $Pre) { | |
Set-StrictMode -Version 2 | |
$ErrorActionPreference = 'Stop' | |
$packageIds = Get-Project -All | | |
% { Get-Package -Project $_.ProjectName } | | |
? { $_.Id -like $IdFilter } | | |
% { $_.Id } | | |
sort -unique | |
$packageIds | % { | |
Write-Host "" | |
Write-Host $_ | |
Update-Package -Id $_ -Pre:$Pre | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment