Prerequisites
Steps to reproduce
Issue
I recently experienced a problem with importing a newer version of Microsoft.PowerShell.PSResourceGet (v1.0.2) than what is included with PowerShell 7.4.1 (v1.0.1):
I started researching and noticed that:
- With Windows PowerShell, included modules are added to a version directory:
%ProgramW6432%\WindowsPowerShell\Modules\<modulename>\<version>\<content>
- PSResourceGet, PowerShellGet and PackageManagement installs modules to:
<installpath>\<modulename>\<version>\<content>.
- PowerShell does not have this version directory for included modules:
%ProgramW6432%\PowerShell\7\Modules\<modulename>\<content>
Is this intentional? Can this cause the issue I experience with PSResourceGet?
My understanding of the issue
It seems that when Import-Module searches through $env:PSModulePath for available modules to import, and stumbles across a module that is not contained in a directory consisting of its' version number, it will lazily import assemblies and thus block importing of any other version of the same module.
Ways to mitigate this
Three different ways to get Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -Version 1.0.2 to work.
- Delete the included module:
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet
- Move included module to a versioned directory:
- From:
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\*
- To:
%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\1.0.1\*
- Reorder
$env:PSModulePath to have the path with the newest version of the module first.
- I do this in my PowerShell profile now.
Expected behavior
PS> Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2
PS>
Actual behavior
PS> Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -RequiredVersion 1.0.2
Import-Module: Assembly with same name is already loaded
PS>
Error details
See: #21201
Environment data
- Windows 11 23H2.
- PowerShell 7.4.1 with Microsoft.PowerShell.PSResourceGet v1.0.1 included/embedded.
- Microsoft.PowerShell.PSResourceGet v1.0.2 installed in some other directory added to PSModulePath.
Visuals
No response
Prerequisites
Steps to reproduce
Issue
I recently experienced a problem with importing a newer version of Microsoft.PowerShell.PSResourceGet (v1.0.2) than what is included with PowerShell 7.4.1 (v1.0.1):
I started researching and noticed that:
%ProgramW6432%\WindowsPowerShell\Modules\<modulename>\<version>\<content><installpath>\<modulename>\<version>\<content>.%ProgramW6432%\PowerShell\7\Modules\<modulename>\<content>Is this intentional? Can this cause the issue I experience with PSResourceGet?
My understanding of the issue
It seems that when
Import-Modulesearches through$env:PSModulePathfor available modules to import, and stumbles across a module that is not contained in a directory consisting of its' version number, it will lazily import assemblies and thus block importing of any other version of the same module.Ways to mitigate this
Three different ways to get
Import-Module -Name 'Microsoft.PowerShell.PSResourceGet' -Version 1.0.2to work.%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\*%ProgramW6432%\PowerShell\7\Modules\Microsoft.PowerShell.PSResourceGet\1.0.1\*$env:PSModulePathto have the path with the newest version of the module first.Expected behavior
Actual behavior
Error details
See: #21201
Environment data
Visuals
No response