xdhmoore
xdhmoore

Reputation: 9915

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?

Upvotes: 0

Views: 114

Answers (1)

mklement0
mklement0

Reputation: 439842

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:

  • Unlike for dependent modules, there is no mechanism to auto-install dependent assemblies - the latter must be bundled via the module or exist in a well-known location on the system.

  • For a proposal to make working with NuGet packages (to consume .NET assemblies) easier in PowerShell, see GitHub issue #6724; that said, given that Install-PSResource is now focused on PowerShell resources only, this may never come to fruition.

Upvotes: 2

Related Questions