Search code examples
c#powershellpowershell-cmdlet

Release C# CmdLet with Powershell Module Manifest


we have a large set of Powershell functions that are written in Powershell and are released using a Powershell manifest file with the following line:

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

Where Module1.psml loops through and imports all of our functions:

#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

We now have a C# cmdlet exposing 1 function that we need to release as part of this. The c# cmdlet contains "Cmdlet1.dll" in the bin directory.

What is the correct way to release this new dll with the module manifest so that when we import Module1, we also get the function from Cmdlet1?

Thank you for any help!


Solution

  • You need to use the NestedModules and CmdletsToExport properties of the manifest file.

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

    I find this page of documentation very helpful in creating a good structure for a project that contains both PowerShell and C# CmdLets.