Integrate PowerShell into Visual Studio with a custom Debug Visualizer

by Doug Finke on December 12, 2007

in Debug Visualizer,PowerShell

A visualizer creates an interface to display a variable or object in a meaningful way.

I am demonstrating an approach for integrating the PowerShell scripting engine into a C# WinForms application and making it available during visual studio debug sessions.

Quick Start

The quickest way to get working is to add these two attributes to your class you want to visualize.

[DebuggerVisualizer(typeof(PoSHVisualizer.PoSHVisualizer))]
[Serializable]

Stepping through your code, any variable defined of this type can be inspected in the visualizer by clicking on the magnifying glass.

The PowerShell visualizer is launched and you have access to the full suite of PowerShell cmdlets, the environment and your object has been injected.

A simple command line editor is presented where you can type PowerShell commands, press F5 and see the results (and errors).

Most importantly your live object is ready to work with in the PowerShell environment and you can act on it directly. Change it, inspect it or Export-Csv it.

Download

I’ve posted the PowerShell Debug Visualizer on CodePlex.

{ 3 comments… read them below or add one }

Steven Murawski 12.13.07 at 10:37 am

Doug,
I love the concept, but I’m having a bit of trouble getting it to work. I’m using VS2008 C# Express and I’ve added the references and decorated the class with the attributes, but it does not seem to like the DebuggerVisualizer attribute.

Any tips would be appreciated.

Thanks!
Steve

Doug Finke 12.13.07 at 1:56 pm

Steve, I will get back to you.

The DLLs were built with 2005.

I have 2008, I’ll test and let you know.

Doug Finke 12.13.07 at 6:26 pm

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>