Skip to content

Instantly share code, notes, and snippets.

@mwallner
Created April 20, 2022 06:34
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 mwallner/9cb37687f7caf5e5f9d5c8f768e098aa to your computer and use it in GitHub Desktop.
Save mwallner/9cb37687f7caf5e5f9d5c8f768e098aa to your computer and use it in GitHub Desktop.
simple script to check if a given choco package and all transitive dependencies are installed
[cmdletbinding()]
param(
$packageName
)
$ErrorActionPreference = 'Stop'
function Test-TransitiveDependencies {
[cmdletbinding()]
param($allPackages, $pkgID)
$pCheck = $allPackages | Where-Object { $_.package.metadata.id -eq $pkgID }
if (-Not $pCheck) {
throw "required package '$pkgId' not present!"
}
else {
Write-Verbose "required package $pkgId is present."
}
if ($pCheck.package.metadata.dependencies) {
foreach ($dep in $pCheck.package.metadata.dependencies.dependency) {
Write-Verbose "$pkgId -> requries '$($dep.id)'"
Test-TransitiveDependencies -allPackages $allPackages -pkgID $dep.id
}
}
}
$allPackages = (Get-ChildItem -Recurse $env:ChocolateyInstall\lib\ -Filter '*.nuspec') | Foreach-Object {
[xml](Get-Content $_.FullName)
}
$pRoot = $allPackages | Where-Object { $_.package.metadata.id -eq $packageName }
Test-TransitiveDependencies $allPackages $pRoot.package.metadata.id
@mwallner
Copy link
Author

note: only checks for ids, no version check is done in this initial version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment