Invoking functions from nested modules in a script module do not always trigger a module to autoload

前端 未结 2 950
逝去的感伤
逝去的感伤 2021-02-08 18:37

If I create a manifest module with nested modules, exported functions from all nested modules after the first do not appear in the list of available commands and don\'t trigger

2条回答
  •  不思量自难忘°
    2021-02-08 19:11

    I had this line in my .psd1 file

    FunctionsToExport = 'FuncFromMainPsm1 FuncFromSecondPsm1'
    

    which was what I inferred from the line generated by Powershell Tools for Visual Studio:

    # Functions to export from this module
    FunctionsToExport = '*'
    

    This caused my Get-Module -ListAvailable to show what looked like the right thing

    Script     1.0        MyMModule                  FuncFromMainPsm1 FuncFromSecondPsm1
    

    But when I called FuncFromSecondPsm1 I'd get "The term 'FuncFromSecondPsm1' is not recognized...".

    So I changed my export line to

    FunctionsToExport = @('FuncFromMainPsm1', 'FuncFromSecondPsm1')
    

    And now it all works. I can call both functions after my module loads, whether via autoload or Import-Module.

    I have tried this with and without both ModuleList and FileList set. They make no difference.

提交回复
热议问题