powershellpowershell-core

PowerShell equivalent for package.json or requirements.txt


Is there an existing convention for listing powershell modules required for a PowerShell project? An equivalent to Python's requirements.txt or Node's package.json, etc? Run command X to 'Install-Module' all requirements?


Solution

  • PowerShell modules specify their dependencies via their module manifests (*.psd1 files).

    It is common for PowerShell modules to be self-contained, i.e. to come bundled with their dependencies.

    However, intra-repository dependencies (on other modules) can be specified via the RequiredModules entry, and should be installed automatically when you use the obsolescent Install-Module command or its successor, Install-PSResource - see this answer for more information.

    The presence of all dependencies is also enforced at import time, whether or not a given module is loaded explicitly, with Import-Module, or implicitly, via module autoloading.


    To list the module and assembly dependencies of a given module (that is either currently loaded or is auto-discoverable, if specified by name only), use:

    Get-Module -ListAvailable $someModule | 
      Select-Object RequiredModules, RequiredAssemblies
    

    Note: