RamblingCookieMonster / BuildHelpers

Helper functions for PowerShell CI/CD scenarios
MIT License
215 stars 47 forks source link

Error with Set-ModuleFunctions when there are ScriptToProcess in the module #45

Closed gaelcolas closed 6 years ago

gaelcolas commented 6 years ago

Interesting issue with ScriptsToProcess... The way the Module is invoked and loaded to extract some information does not work when there are ScriptsToProcess define in the PSD1 (yeah, need them because of scope issues). https://github.com/RamblingCookieMonster/BuildHelpers/blob/master/BuildHelpers/Public/Set-ModuleFunctions.ps1#L54

As you know, ScriptsToProcess are loaded in the session before importing the module, so when you execute this:

Import-Module -Name $Name -PassThru:$Passthru -Force:$Force

It returns the Module info for the ScriptsToProcess then the Module. That means $Parent = $Module.ModuleBase is actually an array of Strings, which ends up voiding $ModulePSD1Path and failing on Update-MetaData -Path $ModulePSD1Path -PropertyName FunctionsToExport -Value $FunctionsToExport.

Not too sure what's the best way to fix it yet, so thought I'd just raise an issue for now :)

nyanhp commented 6 years ago

Hi @gaelcolas , look at PR #47 . I had the exact same issue, and I would assume that this fixes things in a reasonable fashion (it does for me at least)