发布c# CmdLet和Powershell模块清单



我们有大量的Powershell函数,这些函数是用Powershell编写的,并使用Powershell清单文件发布,其中包含以下行:

# Script module or binary module file associated with this manifest.
RootModule = 'Module1.psm1'`

其中Module1.psml循环遍历并导入所有函数:

#Dot source the files
Foreach($import in @($Public + $Private))
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
Export-ModuleMember -Function $Public.Basename

我们现在有了一个c# cmdlet,我们需要发布一个函数作为其中的一部分。c# cmdlet包含" cmdlet .dll"在bin目录下。

用模块清单释放这个新dll的正确方法是什么,以便当我们导入Module1时,我们也从Cmdlet1获得函数?

谢谢你的帮助!

需要使用manifest文件的NestedModulesCmdletsToExport属性

# ...
NestedModules = @('Cmdlet1.dll');
CmdletsToExport = @('CmdletsFromTheDllFile');
# ...

我发现这一页的文档对于创建一个包含PowerShellC#cmdlet的项目的良好结构非常有帮助。

最新更新