Description
We are working on developing few binary Cmdlet modules targeting PWSH Version 6 and above. we are trying to answer some questions (related to a common dependent module) that possible end users of our modules could face when they try out the Cmdlet modules we will be publishing to PSGallery. It would be great if you could advise us. For this example let us assume there are two modules Module A, Module B that provides different functionality but both Module A and Module B depends on some boiler plate code added in Module C (Common module). We can also assume that all Modules (Module A and Modules B) with version 0.1.0 will depend on Module C (Common Module) with the same version (0.1.0). We also intend to do periodic releases of all the modules. Now if an end user wants to do the following:
- Use Module A - 0.1.0 (depends on Module C - 0.1.0) and Module B 0.2.0 (depends on Module C 0.2.0) in the same Powershell session. If the user imports Module A in the session and then tries to import Module B. Pwsh complains "assembly with the same name is already loaded". What can we possibly do let the user use different versions of Module A and module B in the same session?
- This question is not a real problem (as we could open a new PWSH session) but still we are trying to understand why it is happening. We also notice that if we do
Import-Module ModuleA -RequiredVersion 0.1.0
andRemove-Module ModuleA
and later doImport-Module ModuleA -RequiredVersion 0.2.0
. Pwsh complains the same error telling assemblies with the same name is already loaded. Is this becauseRemove-Module
does not remove the loaded assemblies? Is there a work around to load the latest version of the module in the same PWSH session after doing aRemove-Module
?
ModuleA.psd1 contents for version 0.X.0:
RootModule = 'assemblies/ModuleA.dll'
# Version number of this module.
ModuleVersion = '0.X.0'
RequiredModules = @(@{ModuleName = ‘ModuleC’; GUID = ‘xyz’; RequiredVersion = '0.X.0'; })
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = 'assemblies/AnotherDependencyForModuleA.dll'
ModuleC.psd1 contents for version 0.X.0:
# Script module or binary module file associated with this manifest.
RootModule = 'assemblies/ModuleC.dll'
# Version number of this module.
ModuleVersion = ‘0.X.0’
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
RequiredAssemblies = 'assemblies/NLog.dll',
'assemblies/retrier.dll'
Steps to reproduce
Expected behavior
Actual behavior
Environment data