Created
July 4, 2019 11:17
-
-
Save oshvartz/0de94543af64fc53b3c50a4015f52b1c to your computer and use it in GitHub Desktop.
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
function Get-Packages { | |
param( | |
[parameter(Mandatory = $true)][string]$packagePath | |
) | |
$result = @() | |
if ([System.IO.File]::Exists($packagePath)) { | |
[xml]$packages = Get-Content $packagePath | |
foreach ($package in $packages.packages.package) { | |
$result += New-Object PSObject -Property @{ | |
Id = $package.id; | |
Version = $package.version; | |
} | |
} | |
} | |
return $result | |
} | |
function Get-SolutionProjects { | |
param( | |
[parameter(Mandatory = $true)][string]$solutionPath | |
) | |
$solutionProjects = Get-Content $solutionPath | | |
Select-String 'Project\(' | | |
ForEach-Object { | |
$projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') }; | |
New-Object PSObject -Property @{ | |
Name = $projectParts[1]; | |
File = $projectParts[2]; | |
Guid = $projectParts[3] | |
} | |
} | |
return $solutionProjects; | |
} | |
function Get-PackagesNeedsConsoliation { | |
param( | |
[parameter(Mandatory = $true)][string]$solutionPath | |
) | |
$SolutionPath = (get-item $solutionPath).FullName | |
$solutionFolder = Split-Path -Path $solutionPath | |
$solutionProjects = Get-SolutionProjects -solutionPath $solutionPath | |
$allPackages = @() | |
#Get all package | |
ForEach ($solutionProject in $solutionProjects) { | |
$packagePath = Join-Path -Path (Split-Path -Path (Join-Path -Path $solutionFolder -ChildPath $solutionProject.File)) -ChildPath packages.config | |
$allPackages += (Get-Packages -packagePath $packagePath) | |
} | |
$allPackages = $allPackages | Group-Object Id, Version | ForEach-Object { | |
$_ | Select-Object -ExpandProperty Group | Select-Object -First 1 | |
} | |
$allPackages = $allPackages | Group-Object Id | Where-Object { $_.count -gt 1 } | Select-Object Name , Count | |
$needConsolidationPackageNames = @() | |
ForEach ($pck in $allPackages) { | |
$needConsolidationPackageNames += $pck.Name | |
} | |
return $needConsolidationPackageNames | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment