How to debug install.ps1 script of NuGet package

Perhaps I am late to the party but here is a solution for debugging NuGet specific scripts, the NuGet package NuGetDebugTools. Its script Add-Debugger.ps1 adds a simple and yet effective debugger to the NuGet package manager console.

UPDATE: The script is now at PSGallery Add-Debugger. The NuGetDebugTools package is no longer updated. Either use PowerShelf or get individual scripts from the repository.

The sample scenario:

  • start Visual Studio

  • open NuGet console and type commands

      PM> Add-Debugger [-ReadHost]
      PM> Set-PSBreakpoint -Command init
      PM> Set-PSBreakpoint -Command install
    

(or set more specific breakpoints, see help Set-PSBreakpoint)

  • open a Visual Studio solution or invoke Install-Package XYZ for already opened

  • the debugger input dialog appears on any init.ps1 and install.ps1 invoked

  • type ? as debugger input and see what you can do:

      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 empty input).
      q, Quit      Stop operation and exit the debugger.
      ?, h         Display this help message.
      r            Display PowerShell command history.
      k            Display call stack (Get-PSCallStack).
      <number>     Show debug location in context of <number> lines.
      +<number>    Set location context preference to <number> lines.
      <command>    Invoke any PowerShell <command> and write its output.
    
  • type other debugger and PowerShell commands and watch the output in the NuGet console


v1.4.0 – New switch ReadHost tells to use Read-Host for input instead of the default GUI input box.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)