Getting Started with PowerConsole

Visual Studio 2010 is quite an improvement over it’s predecessors in many areas. Extensions for Visual Studio is a big thing and gives you the ability to install simple add-ons that interact and work with your solutions and projects, right from within the IDE. If you’re a tool author and haven’t looked into creating your own extensions you should check out this link to get started.

Here’s a funky little extension called PowerConsole that was written by Jianchun Xu at Microsoft. It’s a PowerShell console window that lives inside of the Visual Studio. Rather than just being a dumb shell, it actually ties into the Visual Studio DTE [explain]. This allows you to access parts of Visual Studio itself like your solution, project, files and even code.

First you’ll need to install the console into Visual Sudio. To do this, select Tools > Extension Manager… from the main menu:

image

Once the Extension Manager dialog appears, select Online Gallery from the left hand navigation:

image

Enter “powerconsole” in the search box and select PowerConsole from the search results:

image

Click on the Download button then click Install when the dialog appears:

image

Some extensions need you to restart Visual Studio after they’re installed. This is one of them. Click on Restart and Visual Studio will shut down and start up again:

image

Once Visual Studio is restarted you’ll have a new window you can open. A PowerConsole window! Click on View > Other Windows > Power Console (or press Ctrl+W then Ctrl+V) to open it:

image

Now the fun begins!

image

With PowerConsole you have access to some of the Visual Studio parts. There’s a built-in variable created for you when PowerConsole loads. Type “$dte” in the PowerConsole and press enter and you’ll see something like this.

image

$dte is the Microsoft Visual Studio object that will give you access to parts of the system, including your own solutions and files.

Now lets load up a solution to play around with. Here’s a blank ASP.NET MVC 2 app. There are a lot of great things you can do with the $dte variable.

$dte.Solution gives you access to the current solution itself:

image

Which you can then parse out and extract say the name of each project and it’s type:

image

The PowerShell Get-Member cmdlet will list all the methods and properties you can access in the $dte object:

image

How about displaying what edition of Visual Studio you’re running?

image

This is just a sliver of what this add-on can do. You also get full Intellisense to your files and any cmdlets you install and there’s extensibility too. There are a ton of things you can do with this and all it takes is a little scripting and some imagination!

Check out the PowerConsole site here and give it a try today.

3 Comments

  • Nice.

  • I would like to know why anyone that knows C# (or pick ur language) would EVER use powershell. I'm serious here, powershell gives you access to all .NET class libraries and such but why would I bother learning a whole new syntax. And risking keeping my objects around for way to long.... (have you read and understood how to dispose of SharePoint objects) I just don't get it so please enlighten me.

    /Jonas

  • Nice article!

    Jonas, I also think that PowerShell has drawbacks. I cannot help, but add to yours' mentioned: the additional "trap" expression for exception handling. But, it gives a unified plugable interface of operating anything on a Windows computer.

    I need to ask, when we could expect to see support for "powershell 2.0" for this extention?! It will be very useful for SharePoint programmers and many others, I guess!

Comments have been disabled for this content.