Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Import-Module fails on default install using EXE installer #77

Open
jeffrey-irwin opened this issue May 20, 2021 · 7 comments
Open

Import-Module fails on default install using EXE installer #77

jeffrey-irwin opened this issue May 20, 2021 · 7 comments

Comments

@jeffrey-irwin
Copy link

jeffrey-irwin commented May 20, 2021

When installing the module via the EXE installer the Import-Module NServiceBus.PowerShell fails with the following error:

Import-Module : The specified module 'NServiceBus.PowerShell' was not loaded because no valid module file was found in
any module directory.
At line:1 char:1
+ Import-Module NServiceBus.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (NServiceBus.PowerShell:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

This looks to be due to there not being a .psm1 file in the module directory and the PSModulePath that is added is direct to the module folder, instead of the parent directory path.
PSModulePath added by EXE installer: C:\Program Files (x86)\Particular Software\NServiceBus.PowerShell\

Workaround:

Add the module parent folder to PSModulePath : C:\Program Files (x86)\Particular Software\

@jeffrey-irwin jeffrey-irwin changed the title PSModulePath incorrect on EXE install Import-Module fails on default install using EXE installer May 20, 2021
@ramonsmits
Copy link
Member

@ji438937 Can you share more about your environment? On what version of Windows and Powershell is this? Also which version of the installer did you use?

@jeffrey-irwin
Copy link
Author

Installer -

@{
	GUID = 'ABFF92C4-A8BA-4CAA-A40D-8C97F3B28934'
	Author = 'Particular Software'
	Description = 'NServiceBus PowerShell'
	ModuleVersion = '6.0.0'
	NestedModules = 'NServiceBus.PowerShell.dll' 
	CLRVersion = '4.0'
	DotNetFrameworkVersion = '4.5.2'
	CompanyName = 'Particular Software'
	Copyright = '(c) 2020 NServiceBus Ltd. All rights reserved.'
	FunctionsToExport='*'
	CmdletsToExport = '*'
	VariablesToExport = '*'
	AliasesToExport = '*'
	FormatsToProcess = @(
    '.\Formats\NServiceBus.Powershell.Cmdlets.InstallationResult.format.ps1xml',
    '.\Formats\NServiceBus.Powershell.Cmdlets.MachineSettingsResult.format.ps1xml'
	)
}

OS -

Caption     : Microsoft Windows Server 2016 Datacenter
BuildNumber : 14393
Version     : 10.0.14393

PowerShell (tested on 2 versions) -

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14393  4402
Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      1      3

@HEskandari
Copy link
Contributor

HEskandari commented Jun 7, 2021

@ji438937 When installing the module, the installer should update a system environment variable called 'PSModulePath' and add an entry to the installation path of the module. This allows the module to get loaded implicitly without you doing an import. Can you check if that has happened? You can check that from the environment variables panel, or by typing $Env:PSModulePath on your PowerShell prompt.

Screen Shot 2021-06-07 at 2 55 01 pm

You can get the list of all installed modules by typing Get-Module -ListAvailable. If the module is listed, you should be able to call the functions without an explicit import, e.g. try calling Test-NServiceBusDTCInstallation. Note that some functions may require elevated access and if you get an error stating that, it means the function is being found correctly.

Screen Shot 2021-06-07 at 3 02 32 pm

@jeffrey-irwin
Copy link
Author

jeffrey-irwin commented Jun 7, 2021

When installing I can confirm that the following path is added/present in the PSModulePath env variable -
C:\Program Files (x86)\Particular Software\NServiceBus.PowerShell\

However, when I attempt to import the module or run commands it fails to find the module -
image

In order for it to work I had to add or adjust the path in PSModulePath to the following (parent folder path) -
C:\Program Files (x86)\Particular Software\

After that, the module loads and I can run commands -
image

I believe this is because PS is looking for a psm1 in the path or a folder with the module name when it tries to import the module. When I look at other modules installed via exe, such as AWSPowerShell, they inject the parent path to PSModulePath.

For now, we are injecting this path during install as a workaround but would prefer if this worked out of the box.

@HEskandari
Copy link
Contributor

HEskandari commented Jun 7, 2021

I think I found the issue. It appears that there's an extra '\' at the end of the path that causes the module not to be discovered. Changing the path from "C:\Program Files (x86)\Particular Software\NServiceBus.PowerShell" to "C:\Program Files (x86)\Particular Software\NServiceBus.PowerShell" and the module is discovered. The higher folder (Particular Software) could have other installations (e.g. ServiceControl management) which is why the installer operates on the inner folders.

image

If you confirm that changing the path fixes the issue, I'll raise an issue to get it fixed.

@jeffrey-irwin
Copy link
Author

With that adjustment Import-Module still fails but the commands work and will auto-import the module when ran -
image

So that is a partial fix - better then before but still not ideal.

Since the parent folder may contain other software I understand the issue there.. Looking at a couple other exe modules, it seems they usually add another folder in the path (PowerShell, Modules, or both PowerShell\Modules) to keep their software separate from their PS modules and then they add that to PSModulePath.
Example -
C:\Program Files (x86)\Particular Software\PowerShell\NServiceBus.PowerShell
Then add 'C:\Program Files (x86)\Particular Software\PowerShell' to PSModulePath

Maybe that is an option here?

Ran a couple quick tests by adding the folder and moving the module folder into it. That works for both Import-Module and running commands without first importing -
image

image

@quetzalcoatl
Copy link

I got here by searching for:

Import-Module : The specified module 'NServiceBus.PowerShell' was not loaded because no valid module file was found in

any module directory.

which I got after using module installer https://github.com/particular/NServiceBus.PowerShell/releases/tag/6.0.0 and running typical command Import-Module NServiceBus.PowerShell

I was able to get it installed on my machine just by using full path instead:

import-module "C:\Program Files (x86)\Particular Software\NServiceBus.PowerShell\NServiceBus.PowerShell.dll"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants