Visual studio extensibility has always been a great feature in Visual Studio and enhance the entire development experience. With Visual Studio 2017, there were a bunch of very substantial changes made with respect to extensibility. Most of these changes comes from the fact that Visual Studio now supports a lighter installation version with bare minimum feature installation as default. There is also the option to have multiple installation on the same machine. So, what does it mean for for extensions?
VS2017 extensions now following the vsix v3 file format. If you have an extension for earlier visual studio versions and you want to port it to VS2017, it means a whole bunch of changes. Here, I am going to write an extension that demonstrate extending Team Explorer. We will create a very simple extension that has a button on Team Explorer, which will open notepad.
Project Creation & Dependencies
Let's start with creating a new extensibility vsix project. You will only see the option if you had selected the VS SDK option while installing visual studio. Let's call our project TeamExplorerExtSample. Visual Studio 2017 uses .Net Framework 4.6.1, so we select this version.
Once the project is created, you will see a couple of web files and a file called source.extension.vsixmanifest, which contains extension information. We will come to this file later.
Now let's add references to the assemblies we would need to extend Team Explorer. Note that with visual studio 2017, assemblies are not added to GAC so we would need to make sure that all desired assemblies are included in the vsix. To display a navigation button in team explorer, we would need to implement the interface ITeamExplorerNavigationItem2, so we would need to add references to the following assemblies
- Microsoft.TeamFoundation.Controls
- System
- System.ComponentModel.Composition
- System.Drawing
VSIX Manifest file:
The manifest file contains information about the extension, it's dependencies, assets and pre-requisites. Double click on the source.extension.vsixmanifest to see details. To extend Team Explorer, the key thing to remember is to add the assembly containing classes that implement Team Explorer interfaces as a MEF component. This will ensure that visual studio loads it up when loading team explorer.
Our VSIX manifest file looks like this
Extending ITeamNavigationItem2
Our extension will create a button in Team Explorer that opens up the notepad application. To do this, we need to extend the ITeamNavigationItem2 interface. The interface is found in Microsoft.TeamFoundation.Control assembly that we have already referenced. We will also need to add TeamExplorerNavigationItem attribute. Our very simple class looks as below.
namespace TeamExplorerExtSample
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using Microsoft.TeamFoundation.Controls;
[TeamExplorerNavigationItem("C9B2CF74-0C87-4CEA-ACA9-8CC1C816D7F3", 1800)]
public class NotepadNavigationItem : ITeamExplorerNavigationItem2
{
public bool IsEnabled => true;
public int ArgbColor => 0;
public object Icon => null;
public string Text => "Open Notepad";
public Image Image => null;
public bool IsVisible => true;
public event PropertyChangedEventHandler PropertyChanged;
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
public void Execute()
{
Process.Start("notepad.exe");
}
public void Invalidate()
{
}
}
}
As you can see, the only matter we have got in the class is a call to Process.Start to start up notepad. The navigation item appears as below
Click on the button and a new instance of notepad opens up.
Conclusion:
Admittedly. this is a very simplistic extension but contains all the steps you need to extend Team Explorer. You can add classes to add Pages, Sections and Links in Team Explorer, add icons \ images and menu items. The code sample from post is here.