Putting the You in Visual Studio 2012's Team Explorer

Description

Today's Weird Wednesday post is not something you'd usually see here, but I thought it pretty cool and is an area that I'm just not seeing much community dev being done in (yet). Maybe today's post will inspire a few of you to jump in!

You may or may not know that I'm a regular co-host on the RadioTFS podcast. One of my roles for cast is gathering Team Foundation Server/Service, Visual Studio, ALM, etc. stores for us to talk about where as you can imagine, that's how I found today's project.

I don't know about you, but I pretty much live in Visual Studio and I'm also a continuous user of Team Foundation Server/Service/CodePlex.

If you've made the jump to Visual Studio 2012, and you're also a TFS/CodePlex user you've seen the new Team Explorer. But do you know just how extensible the new Team Explorer is?

Extending Team Explorer in Visual Studio 2012

Team Explorer in Visual Studio 2012 offers multiple options for extending the user experience. This sample demonstrates several of the extensibility points by adding a new Team Explorer page as well as by placing a new section onto the Pending Changes page.

Team Explorer in Visual Studio 2012 offers multiple options for extending the user experience.  This sample demonstrates several of the extensibility points by:

  • Adding a new "Recent Changes" Team Explorer page with two sections.
  • Adding a new "Selected File Info" section to the built-in Pending Changes page.
  • Adding a "Recent Changes" navigation link under the Pending Changes navigation item.

Building the Sample

This sample requires Visual Studio 2012 and the Visual Studio 2012 SDK.  Open the solution and press F5 to run/debug.

...

One of the nice things about this sample is that everything runs the first time, even to opening Visual Studio is in "Experimental" mode.

That said, if you get a "The application which this project type is based on was not found" or the project won't load or you get "This Project is not compatible with this version of Visual Studio" errors (all of which I got..sigh) then you probably just need to install the Visual Studio 2012 SDK. You can get the latest and greatest from Visual Studio Developer Center > Extend Visual Studio > Download the Visual Studio 2012 SDK.

Once you install the SDK, the Solution and Project should load and when run, should fire up a new instance of Visual Studio with the extension loaded.

So what can you do? Here's a taste;

Team Explorer Extensibility

Pages and Sections

A single view in Team Explorer is referred to as a page (ITeamExplorerPage).  A page may provide a WPF control that is placed at the top of the client area, but the control is not required.  No two pages can have the same ID in Team Explorer.

A page may contain one or more sections (ITeamExplorerSection) that are arranged in priority order.  A section also provides a WPF control that contains the UI for the section.  Sections may be first-party or third-party extensions to a page.

Home Page - Navigation Items and Links

The Home page is a special Team Explorer page that has its own extensibility.  The Home page contains a list of navigation items (ITeamExplorerNavigationItem) and navigation links (ITeamExplorerNavigationLink).  The list of navigation item plugins is used for both the Home page and the Team Explorer navigation control at the top of the window.

Plugin Interfaces

A plugin should implement the interface for the extension it is providing.  The interfaces are declared in the Microsoft.TeamFoundation.Controls namespace in Microsoft.TeamFoundation.Controls.dll.

Page:
ITeamExplorerPage

Section:
ITeamExplorerSection

Navigation Item:
ITeamExplorerNavigationItem

Navigation Link:
ITeamExplorerNavigationLink

But what exactly does this sample provide?

  • Adding a new "Recent Changes" Team Explorer page with two sections.
  • Adding a new "Selected File Info" section to the built-in Pending Changes page.
  • Adding a "Recent Changes" navigation link under the Pending Changes navigation item.

Oh, screenshots? Here's some before and after snaps

Recent Changes

image

image

Selected File Info

image

image

Pending Changes/Recent Changes

image

As you can see, the new extensibility lets you seamlessly add features and functionality to the new Team Explorer.

How does it work? MEF of course!

Plugin Discovery

Plugin discovery for Team Explorer is accomplished using MEF.  The assembly containing any plugins must be installed in one of Visual Studio’s supported extension directories, and must be accompanied by an extension.vsixmanifest file that declares the assembly provides MEF components.  The recommended packaging mechanism is using VSIX and the Visual Studio Extension Gallery.

There is a class attribute for each plugin type that exports the plugin for discovery by Team Explorer.  The attributes are defined in the Microsoft.TeamFoundation.Controls namespace in Microsoft.TeamFoundation.Controls.dll.

Page:
     [TeamExplorerPage("guid")]

Section:
     [TeamExplorerSection("guid", "parentPageGuid", priority)]

Navigation Item:
     [TeamExplorerNavigationItem("guid", priority)]

Navigation Link:
     [TeamExplorerNavigationLink("guid", "parentNavigationItemGuid", priority)]

But Greg, what about the impact these kinds of plugins could have on Visual Studio? I don't want to go back to the old days where extension bloat killed performance!

Plugin Lifetime

No page or section will be instantiated until the user navigates to it for the first time.  The page and all of its sections are then instantiated and then initialized in priority order.  A page or section is only initialized once during its lifetime.  The Initialize method is the appropriate time to query for any services and do any initialization for child controls.  EventArgs provide an IServiceProvider as well as optional initial page context.

In order to manage memory efficiently, only the current page is held in memory at any given time.  When the user navigates to a new page, the current page will have its SaveContext method called in order to preserve any context, and then it is closed.  See the "Context Management" section for more discussion on how that context object is managed.

What about Context Management? Covered. Sharing Info: Data, Selection, Etc? Covered. Navigation, Notifications? Covered.

Okay, how much code is there? Here's a snap of the Solution

image

The references?

image

So are you a little interested at least? Hungry for more information? Here's the starting point for all things Extending Team Foundation (both client and server).

If you create the next great Team Explorer extension, drop us a line at ch9@microsoft.com!

The Discussion

  • User profile image
    Mahesh

    Please Help. I have a problem to run this program view this message
    Unable to start program 'c\users\name\documents\visual studio 2012\Projects\project2\debug\project2 exe. and the system cant find the file specified

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.