Create a manifest for nested PowerShell modules

2020-06-18 03:57发布

问题:

I'm having a minor issue with nested, PowerShell modules.

Get-Module correctly identifies the ExportedCommands, but the ModuleType is listed as Script, rather than Manifest:

PS>get-module

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Script     Bar                       Get-Bar
Script     Foo                       Get-Foo

Directory structure:

|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar
      |-Bar.psm1
    |-Foo
      |-Foo.psm1

Foobar.psd1:

...
# Script module or binary module file associated with this manifest
ModuleToProcess = ''

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo\Foo.psm1', 'Bar\Bar.psm1'
...

Have I structured the PSD1 file correctly? In my situation, do I need a dummy/empty Foobar.psm1 file (with corresponding entry in PSD1 file)? Do I need the nested directory structure, or can I just include the two PSM1 files (bar.psm1 and foo.psm1) in the parent directory (Foobar)?

回答1:

Directory structure needed to be:

|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar.psm1
    |-Foo.psm1

Foobar.psd1 needed to be :

...
# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo.psm1', 'Bar.psm1'
...