powershell - 如何在 PowerShell 模块 list (psd1) 中定义 RequiredModules?

标签 powershell module manifest

我正在尝试在两个 PowerShell 模块之间创建一个简单的依赖关系,但我遇到了语法或错误。
Module1.psd1 :

@{
    RootModule        = 'Module1.psm1'
    ModuleVersion     = '1.0'
    GUID              = '11111111-1111-1111-1111-111111111111'
    Author            = 'uw'
    FunctionsToExport = @()
    CmdletsToExport   = @()
    VariablesToExport = '*'
    AliasesToExport   = @()
}
Module2.psd1 :
@{
    RootModule        = 'Module2.psm1'
    ModuleVersion     = '1.0'
    GUID              = '22222222-2222-2222-2222-222222222222'
    Author            = 'uw'
    FunctionsToExport = @()
    CmdletsToExport   = @()
    VariablesToExport = '*'
    AliasesToExport   = @()
    RequiredModules   = @(
                          @{
                            ModuleName = "Module1"; 
                            ModuleVersion = "1.0"; 
                            Guid = "11111111-1111-1111-1111-111111111111"
                           }
                         )
}
Module2 的模块 list 定义 Module2取决于 Module1 .

运行时Test-ModuleManifest Module2.psd1 ,我收到以下错误:
Test-ModuleManifest : The specified RequiredModules entry 'Module1' in the module manifest 'Module2.psd1' is invalid. 
Try again after updating this entry with valid values.

最佳答案

问题原来是 Test-ModuleManifest期望所有必需的模块都安装在本地系统上。

所以解决方法是安装 Module1 ,然后验证 Module2 的 list .

https://github.com/PowerShell/PowerShellGet/blob/90c5a3d4c8a2e698d38cfb5ef4b1c44d79180d66/Tests/PSGetPublishModule.Tests.ps1#L1470 .

关于powershell - 如何在 PowerShell 模块 list (psd1) 中定义 RequiredModules?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46216038/

相关文章:

android - 选项卡布局教程不完整?

java - 使用 Netbeans 将示例应用程序打包并作为 JAR 运行

string - PowerShell 中 "System.Version"的版本字符串太长(或太短)

oracle - 在 Linux 中使用 PowerShell 连接到 Oracle Autonomous db

magento - 无效的配置字段后端模型: adminhtml/system_config_backend_web_secure_offloaderheader

office365 - 仅在 Web 版办公产品上启用 Office 加载项

regex - 如何在我的替换语句中检索 powershell 中对象的值?

powershell - PowerShell-10条记录后退出ForEach-Object

javascript - 如何在 Node 中模拟 require.main?

python - 如何将 Python 包编译为 dll