Open SteveL-MSFT opened 1 year ago
Not every cmdlet mentioned in a script has a chance to be called on the current system. Simple scanning might give false positives when the ps1 contains multiple system-dependent implementations. Those cases remind conditional compilation in C* languages.
# … some code …
if ($IsWindows -and $aConditionEvaluatedInTheCodeAbove) {
# … use Windows specific dependencies …
} elseif ($IsLinux) {
# … use Linux specific dependencies …
}
Does this functionally actually need to exist? I say that because it seem this functionality is already covered when author creates the script/module and defines the dependencies in the PSScriptFileInfo
comment block or RequiredModules
key in the module manifest.
Solving for conditionals might not be in scope for this suggested script, but we'd like to get more feedback from the community.
Sure, the scope should be under control. At the same time there is a good reason for Resolve-Dependency
to keep a good distance from forcing users to install unnecessary dependencies.
Summary of the new feature / enhancement
Maybe call it
Resolve-Dependency
which takes a path to a ps1 (or psm1), uses PowerShell to parse to AST extracting all the commands and seeing if they are actually available on the current system.If it's a cmdlet and not on the system, discover which module via PowerShellGet to install for that cmdlet or if a native command, just give a warning message that it wasn't found on the system. For security, make it clear if the module is from an untrusted repository.
Proposed technical implementation details (optional)
No response