Remko
Remko

Reputation: 7340

Manifest not processed when loading module

I've created a PowerShell module and a manifest but it seems like the manifest is not processed when loading the module.

I've created a very simple example with the same behaviour:

TestModule.psm1

function Foo
{
    return "Bar"
}

I then create a manifest like this:

$version = New-Object System.Version(0, 0, 1, 0)

New-ModuleManifest -Author "Remko Weijnen" -Description "TestModule" -ModuleVersion $version  -PowerShellVersion 3.0 `
    -Path ".\TestModule.psd1" -RootModule ".\TestModule.psm1"

I've created a folder TestModule and placed TestModule.psm1 and TestModule.psd1 inside it.

When importing the manifest the version is recognised correctly:

Import-Module .\TestModule.psd1
Get-Module TestModule | select name, version

Name       Version
----       -------
TestModule 0.0.1.0

However when I load the module the version is not recognised:

Import-Module .\TestModule.psm1
Get-Module TestModule | select name, version

Name       Version
----       -------
TestModule 0.0

Am I missing something? Or is it not supposed to work like this?

Upvotes: 3

Views: 2067

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36342

This is pretty much how you should expect it to work. When you explicitly import the .psm1 file you bypass the manifest. There's nothing in the .psm1 file that says to load the manifest. If you follow "normal" module behavior (by "installing" the module to a path listed in the modulepath environmental variable) then the manifest is loaded as expected.

Upvotes: 4

Related Questions