自定义dll的导入模块失败

本文关键字:模块 失败 导入 dll 自定义 | 更新日期: 2023-09-27 18:00:32

我在这里完成了创建自定义powershell cmdlet的演示。当我尝试导入模块时,我得到以下错误:

C:'PS> Import-Module DemoPS.dll
Import-Module : The specified module 'DemoPS.dll' was not loaded because no valid module file was found in any module directory.

如果需要更多信息,请告诉我。

自定义dll的导入模块失败

显示错误是因为它找不到您的dll文件。您需要为模块DLL文件(例如Import-Module c:'users'mj'desktop'DemoPS.dll)指定完整路径。

作为替代解决方案,您可以将其保存在"模块"文件夹中。这是一个名为"模块"的文件夹,您必须在配置文件目录中创建它。您的配置文件目录可以使用$profile找到。通常在C:'Users'<username>'Documents'WindowsPowerShell'中。所以要使用这个,请将您的dll放在以下路径中:

C:'Users'<username>'Documents'WindowsPowerShell'Modules'DemoPS'DemoPS.dll