How to debug install.ps1 script of NuGet package

后端 未结 5 410
闹比i
闹比i 2020-12-22 22:52

So we can include an install/uninstall powershell scripts in a NuGet package. I tried, but my install.ps1 does not work. Is there any possibility to find out why? Debugging,

5条回答
  •  醉话见心
    2020-12-22 23:33

    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.

    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).
           Show debug location in context of  lines.
      +    Set location context preference to  lines.
          Invoke any PowerShell  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.

提交回复
热议问题