8
Vote

Debugging scripts run by a custom PowerShell host

description

Enable debugging PowerShell scripts (with breakpoints etc) that are run by a custom PowerShell host (e.g. one written in C#)
Debugging PowerShell scripts currently only works when PowerGUI is the host (in PowerGUI VSX with the VS PowerShell project or in standalone PowerGUI)
 
E.g. I'm using several custom hosts in the http://solutionsfactory.macaw.nl to call PowerShell scripts from C#. I have a host in a VS 2010 extension and one in a custom MSBuild task. These scripts talk to the VS object model and are currently very hard to debug.
Also think of debugging NuGet PowerShell scripts...
 
Ideally I would like to be able to 'attach' a PowerShell debugger to any running process (including a VS instance) that invokes PowerShell scripts from a custom PowerShell host, same as debugging C#.
Then you could use PowerShell as a language in any C# project type and get the best of both worlds, e.g. also in a web application, web service, SharePoint or BizTalk components etc.
 
If this would require modifying my hosts (e.g. with code / dlls provided by PowerGUI) and/or C# project files I'd do that without hesitation.
Having no debugging is now a serious maintainability limitation for using PowerShell anywhere, it would be great if PowerGUI would remedy this.

comments

RomanKuzmin wrote Feb 9, 2014 at 8:00 AM

I recently had to debug NuGet scripts and was rather surprised that the NuGet package manager console does not provide any debugger. I also did not find any 3rd party tools that can be used easily. Thus, I am also interested in this feature and have voted up.

Meantime, in order to solve the tasks now I created a simple and yet effective debugger (just a single PowerShell script) and was able to use it for debugging NuGet scripts right in the NuGet console. The debugger is somewhat similar by nature to the Microsoft PowerShell console debugger. Hopefully it can be useful for somebody else, too.

The script Add-Debugger.ps1 included to the NuGet package NuGetDebugTools:
https://www.nuget.org/packages/NuGetDebugTools/