Debugging Scripts
Debugging PowerShell Scripts with PowerShell ISE
Open the 64-bit bit version of PowerShell ISE.
Enter the PowerShell host process of Playnite:
Enter-PSHostProcess -Name Playnite.DesktopApp
Identify the correct runspace name of your script. It will be the name of the module file. Use the commands
Get-Runspace
or(Get-Runspace).Name
to list runspaces.Debug the script by attaching to the runspace:
Debug-Runspace -Name "LibraryExporter.psm1"
The debugger will automatically break when code is executed. A tab named "[Remote File] LibraryExporter.psm1 [Read Only]" will appear in PowerShell ISE. To trigger the debugger to break, interact with the extension somehow. For example, click the Playnite menu button to break in
GetMainMenuItems
.Set breakpoints using Debug > Toggle Breakpoint.
Continue execution by selecting Debug > Run/Continue.
When the breakpoint is reached, hover over any variable names to see their current value.
Typing into the PowerShell ISE console will evaluate statements in the current context. For example, you can use the $PlayniteAPI
variable to interactively develop and test code. You may also interactively inspect local variables and their properties.
The Playnite interface will appear frozen while the debugger is paused on a breakpoint.
Interactive PowerShell console
You can start PowerShell instance with pre-loaded Playnite SDK from main menu -> extensions. This will open PowerShell console connected to Playnite process and initialize new runspace for this interactive session.
To get Playnite API object use CTRL-V shortcut and ENTER (there's currently no better way how to do this, sadly). This will initialize two variables:
$PlayniteApi
which is an instance of Playnite API object.$PlayniteRunspace
which is PowerShell runspace running in Playnite process dedicated to this interactive "playground".
You can also access runspace of every installed and loaded PowerShell extension via Get-Runspace
cmdlet.