【问题标题】:Powershell not importing functions from modulePowershell不从模块导入函数
【发布时间】:2016-12-15 17:50:40
【问题描述】:

我正在尝试在此处设置 NuGet 提要,并且效果很好。我通过

从我的提要中安装了一个模块
Install-Module -Name MyCmdlets -Repository $RepoName -Scope CurrentUser -Force
Import-Module -Name MyCmdlets

但是,当我运行 Get-Module 时,我没有得到任何功能,而且它是一个清单?

ModuleType Version    Name                                ExportedCommands                                  
---------- -------    ----                                ----------------                                  
Manifest   1.0        MyCmdlets          

如果我手动转到安装位置并手动导入

Import-Module <my-path>\1.0\MyCmdlets.psm1                 

ModuleType Version    Name                                ExportedCommands                                  
---------- -------    ----                                ----------------                     
Script     0.0        MyCmdlets                      {Create-Project, Get-AuditLogs, Get-..             

我的清单文件确实有这些行,所以我不明白为什么 Import-Module 不能正常工作。

FunctionsToExport = '*'

CmdletsToExport = '*'

【问题讨论】:

    标签: powershell module cmdlets powershell-module powershellget


    【解决方案1】:

    我猜你没有像这样在你的 .psd1 中设置根模块

    #
    # Module manifest for module 'YourModule'
    #
    
    @{
    
    # Script module or binary module file associated with this manifest
    RootModule = 'YourModule.psm1'
    
    # Version number of this module.
    ModuleVersion = '1.0.0'
    
    ...
    

    这是必要的,因此当您导入清单模块时,它也会加载脚本模块

    【讨论】:

    • 谢谢!不敢相信我错过了。以后我需要更多地查看清单文件。
    • 我知道,因为几周前我也做过同样的事情:D
    【解决方案2】:

    对于遇到此问题并寻找其模块无法导入的原因的任何人,请检查 RootModule = 'YourModule.psm1' 是否被注释掉。 默认情况下,当使用 New-ModuleManifest 创建新清单时,它会在此行前面抛出一个哈希值..

    呃,我觉得我很愚蠢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 2019-11-14
      • 2022-11-11
      • 2016-11-12
      • 1970-01-01
      • 2022-01-15
      相关资源
      最近更新 更多