Issue Importing Module from Gallery

Welcome Forums General PowerShell Q&A Issue Importing Module from Gallery

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #108239

    Participant
    Points: -19
    Rank: Member

    We are moving our standalone scripts into modules. We have created a module that uses nested modules. The module itself is just a utility that contains the nested modules.  The structure is like this:

    Utility\
    Utility.psd1
    DoSomething\
    Get-Something.psm1

    In the manifest we have set up the nested module information like so

    NestedModules = @('DoSomething\Get-Something.psm1')
    FunctionsToExport = '*'
    # ModuleList = @()

    Test-ModuleManifest says everything is fine. Using Import-Module to load the module works. Get-Command -Module Utility displays the command(s) correctly. Executing them works. So as far as I can tell everything is working correctly.

    Now we generate a NuGet package for the module and upload it to our private gallery.  I am able to see the module in the repo via Find-Module. I am able to install it using Install-Module.  I go to the %Program Files%\WindowsPowershell\modules path and it has properly extracted it to the required layout that is recommended. Everything looks great.

    Now I try to run Import-Module and I get the error – import-module : The specified module 'Fsmb.Utility' was not loaded because no valid module file was found in any
    module directory.

    Trying to use Get-Command on the module shows no commands.

    What would be preventing this from working when installed via a repo vs importing it directly?

    Note that I've also tried setting (in the manifest) ModuleList to the same set of values as NestedModules. It had no effect. Since redeploying to the repo is a pain I simply edited the .psd1 file that was installed into the folder mentioned earlier. So unless PS is caching the manifest data somewhere it should have detected the module list.

     

  • #108413

    Participant
    Points: 7
    Rank: Member

    Take a look at this article for guidance to make sure you are correctly packaging your modules.

    https://refactorsaurusrex.com/post/2017/composing-a-powershell-module-from-multiple-script-files/

  • #108697

    Participant
    Points: -19
    Rank: Member

    That looks like what I've already done. Again, the layout is identical when I build out the module on disk and when it gets installed via the gallery. The only difference between the 2 is the target location. When importing/testing the module in the local directory it works fine. It only fails (with the same exact directory structure and manifest) when it is installed via the gallery.

  • #108745

    Participant
    Points: -19
    Rank: Member

    I have figured out what is going wrong. The module is being hosted in a NuGet repository that has been configured. In the nuspec file it is using semantic versioning (e.g. 1.2. 3) since that is what NuGet uses. However in the generated manifest file it uses a full version number (e.g. 1.2.3.0).

    When the module is installed it generates a folder structure that uses the semantic version #. When PowerShell tries to find the module it is using the full version and isn't finding it so it fails.

    The fix is to ensure that both the Nuspec and manifest file are using the same semantic version (e.g. 1.2.3).

The topic ‘Issue Importing Module from Gallery’ is closed to new replies.