0

EDIT

I added the path to the dll in the RootModule

 RootModule = './bin/Debug/net8.0/PSInvestigator.dll'

section of the .psd1 and it worked. I can confirm that PlatyPS is the way to go for writing PowerShell binary file documentation

I have a PowerShell C# binary called PSInvestigator with the directory structure PSInvestigation/PSInvestigator/ and the files PSIUptime.cs, PSIPartitions.cs etc

I can run and execute the c# .dll no problem in PowerShell by doing

dotnet build
ipmo /home/deca/RiderProjects/PSInvestigator/PSInvestigator/bin/Debug/net8.0/PSInvestigator.dll

Then I can run my commands like Get-PSIVersion this has all worked fine. But now I want to add help to my C# PowerShell cmdlets. It looks like I need to add a .psd1, and en-us folder with the xml help files, and a psm1. My directory looks like this now

PS ~/RiderProjects/PSInvestigator/PSInvestigator> tree .                                                                                         
.
├── bin
│   └── Debug
│       └── net8.0
│           ├── PSInvestigator.deps.json
│           ├── PSInvestigator.dll
│           └── PSInvestigator.pdb
├── en-us
│   └── PSIPartitions-Help.xml
├── PSICmdline.cs
├── PSInvestigator.csproj
├── PSInvestigator.psd1
├── PSInvestigator.psm1
├── PSIPartitions.cs
├── PSIUptime.cs
└── PSIVersion.cs

I generated my .psd1 using the NewModuleManifest PowerShell cmdlet and I made sure to add these lines to it exported all the functions and specifying the .psm1 file. I'm not actually sure if I need the .psm1 file though.

# Script module or binary module file associated with this manifest.
RootModule = 'PSInvestigator.psm1'
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @("./bin/Debug/net8.0/PSInvestigator.dll")
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = '*'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = '*'

I added this to the .psm1 file but I've tried imported the module both with and without the .psm1 file and neither option has worked

# Get the directory of the script
$scriptDirectory = $PSScriptRoot

# Load the assembly
$assemblyPath = Join-Path -Path $scriptDirectory -ChildPath "bin/Debug/net8.0/PSInvestigator.dll"
Add-Type -Path $assemblyPath

# Exported cmdlets and functions
Export-ModuleMember -Function * -Cmdlet *

Now when I run import-module ./PSInvestigator.psd1 and execute Get-Module I don't see any exported commands

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.0.1                 PSInvestigator      

If I just run import-module on the full path /home/deca/RiderProjects/PSInvestigator/PSInvestigator/bin/Debug/net8.0/PSInvestigator.dll everything works. What do I need to do to get the PowerShell Module and it's documentation to be imported correctly?

1
  • 1
    You definitely do not need a psm1 for a binary module. Your RootModule should be the relative path to your assembly. as for the help, it seems correctly placed. As long as it is a valid xaml, generally the easiest way to generate your help file is using platyPS converting your md (markdown files) to that single XML as you have, then PowerShell should correctly load the cmdlet's help. If you do need a psm1 for some reason, then your current issue is that you're using Add-Type to the dll instead of Import-Module to the dll Commented May 27, 2024 at 22:21

1 Answer 1

0

You definitely do not need a psm1 for a Binary Module. In your psd1 the RootModule should be the relative path to your assembly.

As for the help, it seems correctly placed. As long as it is a valid XAML, generally the easiest way to generate your help file is using platyPS Module converting your md files (from New-MarkdownHelp) to a single XML with New-ExternalHelp as you have, then PowerShell should correctly load the cmdlet's help.

If you do need a psm1 for some reason, then your current issue is that you're using Add-Type to load the assembly instead of Import-Module, then it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.