Skip to content

Debug psm1 files. #133

Closed
Closed
@elangelo

Description

@elangelo

Hi,

I can't find a standard way to debug functions in psm1 files.
I've hacked together that more or less works for me now but it's incomplete:

  1. adjust launch.json:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "PowerShell",
            "type": "PowerShell",
            "request": "launch",
            "program": "Invoke-PSake",
            "args": ["${workspaceRoot}\\Debug.ps1", "Debug", "-parameters @{\"ModuleFile\"=\"${file}\"}"]
        }
    ]
}
  1. add Debug.ps1
`properties{
    $ModuleFile
}

Task Debug {
    echo "debugging"
    Import-Module $ModuleFile
    $moduleName = [io.path]::GetFileNameWithoutExtension($ModuleFile)
    $command = Get-Command -Module $moduleName

    if ($command.Length -gt 1) {
        Write-Host "More than one exported command in the module you want to debug."   
    } else {
    & $command
    }
}`

This works rather well if you are debugging modules with only one exported command and that doesn't require any parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions