Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug install.ps1 script of NuGet package

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, logging, anything?

Update

Please note that the script is executed as part of an installation process of Nuget package. It may be very Nuget-specific.

like image 610
dkl Avatar asked Aug 11 '11 19:08

dkl


People also ask

How do I debug a NuGet package?

In order to debug into NuGet package libraries, Visual Studio must be configured to use ProGet as a symbol server. To do this select Debug > Options, from the menu bar, then browse to Debugging > Symbols in the tree menu.

How do I Download a Nupkg file?

Either make an account on the Nuget.org website, then log in, browse to the package you want and click on the Download link on the left menu. Then simply unzip the . nupkg file and extract the contents you need.


1 Answers

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). <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.

like image 167
Roman Kuzmin Avatar answered Sep 16 '22 20:09

Roman Kuzmin