Forked from Kevin-Bronsdijk/NuGet-Consolidation-package-with-different-versions.ps1
Last active
October 24, 2023 16:05
-
-
Save ddpruitt/f79af2ed187f6a99974dc06e336b6f78 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
class Package | |
{ | |
[String]$id | |
[String]$version | |
[String]$targetFramework | |
[String]$path | |
} | |
function GatherPackageInfo([string]$path) { | |
$packages = @() | |
[xml]$XmlDocument = Get-Content -Path $path | |
Foreach($p in $XmlDocument.Packages.package) { | |
$pak = New-Object Package | |
$pak.id = $p.id | |
$pak.version = $p.version | |
$pak.targetFramework = $p.targetFramework | |
$pak.path = $path | |
$packages += $pak | |
} | |
return $packages | |
} | |
function FindAllProjectFiles ([string]$sourceFolder) | |
{ | |
$allPackages = @() | |
$filesToWorkWith = gci $sourceFolder -recurse -filter "packages.config" -file -ErrorAction SilentlyContinue | |
ForEach ($file in $filesToWorkWith) | |
{ | |
$allPackages += $packages = GatherPackageInfo($file.FullName); | |
} | |
return $allPackages | |
} | |
function ListPackagesWithMultipleVersions ([string]$sourceFolder) | |
{ | |
$allresults = FindAllProjectFiles($sourceFolder) | |
return $allresults | group -p id | | |
where { $_.count -ge 2 } | % { $_.Group } | | |
sort -u id, version | | |
group -p id | | |
where { $_.count -ge 2 } | % { $_.Group } | | |
sort -u id, version | |
} | |
function CheckIfPackageExits ([string]$sourceFolder, [string]$filter) | |
{ | |
$allresults = FindAllProjectFiles($sourceFolder) | |
return $allresults | where {$_.id -Like $filter} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment