How to debug NuGet package scripts

You can step by step debug your Init.ps1, Install.ps1, or Uninstall.ps1 using NuGetDebugTools. It won’t be the best debugging experience you’ll ever have in your life, but it will surely get the job done!

At first you need to open the Package Manager Console in Visual Studio and:

  1. install the NuGetDebugTools package
  2. add the debugger
  3. set breakpoints for the scripts  you want to debug

Now you’re all set and you can begin installing your own package. Depending on which breakpoints you’ve set with the Set-PSBreakpoint command, when a break point gets hit you will be prompted with a dialog. This is where you will be entering your commands debugging commands (e.g. s for step into, v for step over)



Dialog for entering debugging commands

The basic commands that you can enter are

  • s – StepInto (Step to the next statement into functions, scripts, etc)
  • v – StepOver (Step to the next statement over functions, scripts, etc)
  • o – StepOut (Step out of the current function, script, etc)
  • c – Continue (Continue operation, also on Cancel or empty)
  • q – Quit (Stop operation and exit the debugger)
  • ?, h – Help (Write this help message)
  • k – CallStack (Write call stack, aka Get-PSCallStack)
  • K – CallStackDetailed (Write detailed call stack using Format-List)

And you will be receiving feedback and additional information in the Package Manager Console

You can find an exhaustive list of commands and more detailed information on the NuGetDebugTools github page