I have an .NET assembly that will get imported by a Powershell session using:
Import-Module MyAssemblyFirst.dll
What I need is to automatically load another custom assembly (MyAssemblySecond.dll
) that I know about when MyAssemblyFirst.dll
gets imported.
The scenario I am looking for is:
Import-Module MyAssemblyFirst.dll
Import-Module MyAssemblySecond.dll
but I would rather like to have only one Import-Module
call:
Import-Module MyAssemblyFirst.dll
...and somehow to trigger loading the second assembly as well.
The 2 assemblies do not reference each other but I am the owner of both. I'm just trying to simplify importing multiple assemblies by importing only one.
So in a broader example, I am looking to simplify a PS script like this:
Import-Module MyAssemblyFirst.dll
Import-Module MyAssemblySecond.dll
Import-Module MyAssemblyThird.dll
...
Import-Module MyAssemblyNth.dll
to a single line:
Import-Module MyAssemblyFirst.dll
EDIT: The purpose for this is that based on a certain logic located in MyAssemblyFirst.dll I might want to automatically import some other assemblies that expose some new specific PS commands.
You can implement
IModuleAssemblyInitializer
interface to provide module initialization code: