Powrshell:只能加载最新模块中的类



环境:


Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

代码:

#testmodule1.psm1
Class TestClass1
{
}
#testmodule2.psm1
Class TestClass2
{
}

然后在命令行:

PS C:datacwd> [testclass1]
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    TestClass1                               System.Object
PS C:datacwd> using module testmodule2
PS C:datacwd> [testclass2]
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    TestClass2                               System.Object
PS C:datacwd> [testclass1]
InvalidOperation: Unable to find type [testclass1].

似乎随着第二个模块的加载,第一个模块中的类已从内存中清除你能给我建议吗?

将其用作SINGLE命令using module '$SomePathtestmodule1.psm1'; using module '$SomePathtestmodule2.psm1'

else指令使用模块$SomePath\testmodule1.psm1替换为$SomePath\testmodule2.psm1

最新更新