【发布时间】:2018-01-23 14:34:23
【问题描述】:
我想嵌套多个模块/脚本,我想将实际文件保存在多个目录中:
BuildTests[dir]
|BuildTests.psd1
|GenericTests[dir]
||GenericTests.psd1
||GenericTest1.ps1
||GenericTest2.ps1
|SpecificTests[dir]
||SpecificTests.psd1
||SpecificTest1.ps1
||SpecificTest2.ps1
我想为每个 .ps1 文件保留 1 个函数。
我尝试了以下方法:
在 BuildTests.psd1 中定义NestedModules = @('.\GenericTests\GenericTests.psd1','.\SpecificTests\SpecificTests.psd1')
在 GenericTests.psd1 中定义 ScriptsToProcess = @('GenericTest1.ps1','GenericTest2.ps1')
相应地配置SpecificTests.psd1
基本上这是可行的,但是在检查 get-module 时,我看到两次导入的 .ps1 文件中的所有功能,使用 -verbose 参数进一步检查 import-module,我可以看到一次是“正在加载模块...... test1.ps1”,下一行是“Dot-Sourcing the script file ....test1.ps1”。
我在 .psd1 中尝试了不同的变体(从 .ps1 更改为 .psm1 并将它们包含在嵌套模块中),但我似乎总是以导入重复或根本没有导入任何函数而告终。
【问题讨论】:
-
“每个 .ps1 文件 1 个函数”的任何原因?
-
为了方便,也可以是 .psm1 文件
标签: powershell nested