diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 105704fb256..f47f9b45e48 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -1620,7 +1620,17 @@ internal PSModuleInfo LoadModuleManifest( if (bailOnFirstError) return null; } - string resolvedCommandPrefix = BasePrefix ?? defaultCommandPrefix ?? string.Empty; + string resolvedCommandPrefix = string.Empty; + + if (!string.IsNullOrEmpty(defaultCommandPrefix)) + { + resolvedCommandPrefix = defaultCommandPrefix; + } + + if (!string.IsNullOrEmpty(this.BasePrefix)) + { + resolvedCommandPrefix = this.BasePrefix; + } if (!string.IsNullOrEmpty(actualRootModule)) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Import-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Import-Module.Tests.ps1 index 2cc21dc03f3..6885abe847d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Import-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Import-Module.Tests.ps1 @@ -57,18 +57,6 @@ Describe "Import-Module" -Tags "CI" { (Get-Module TestModule).Version | Should -BeIn "1.1" } - - It 'Should override default command prefix if an empty string is provided' { - $ModuleName = "PrefixTestModule" - $ModulePath = Join-Path -Path $testdrive -ChildPath $ModuleName - $null = New-Item -Path $ModulePath -ItemType Directory -Force - 'function Use-Something{}' | Set-Content -Path "$ModulePath\$ModuleName.psm1" -Force - New-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" -DefaultCommandPrefix MyPrefix -FunctionsToExport Use-Something -RootModule "$ModuleName.psm1" - $ImportedModule = Import-Module -Name "$ModulePath\$ModuleName.psd1" -Prefix "" -PassThru - $ImportedModule.ExportedCommands.ContainsKey('Use-Something') | Should -Be $true - Remove-Module -ModuleInfo $ImportedModule - } - It 'ProcessorArchitecture should work' { $currentProcessorArchitecture = switch ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) { 'X86' { 'x86' }