本文介绍了为嵌套的 PowerShell 模块创建清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了嵌套 PowerShell 模块的小问题.

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

Get-Module 正确识别了 ExportedCommands,但 ModuleType 被列为 Script,而不是 :

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

目录结构:

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

Foobar.psd1:

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'
...

我是否正确构建了 PSD1 文件?在我的情况下,我是否需要一个虚拟/空的 Foobar.psm1 文件(在 PSD1 文件中有相应的条目)?我需要嵌套的目录结构,还是可以只在父目录 (Foobar) 中包含两个 PSM1 文件(bar.psm1 和 foo.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)?

推荐答案

需要的目录结构:

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

Foobar.psd1 需要:

Foobar.psd1 needed to be :

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

这篇关于为嵌套的 PowerShell 模块创建清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:31