I'm trying to add Git support to my Visual Studio 2015 extension Diff All Files. I have everything working properly for the TFVC Team Explorer pages, and am trying to now have my extension show up on the Git Changes and Git History pages as well. In order to be able to detect the pending changes on the Git Changes page I need to get a handle to the IChangesExt service. This page shows how to do it, but for some reason it does not work for me; I always just get a null value returned back, and not the expected IChangesExt instance.
Here's the relevant code snippets from that site:
Microsoft.TeamFoundation.Controls.ITeamExplorer teamExplorer;
teamExplorer = base.GetService(typeof(Microsoft.TeamFoundation.Controls.ITeamExplorer)) as Microsoft.TeamFoundation.Controls.ITeamExplorer;
Microsoft.TeamFoundation.Controls.ITeamExplorerPage teamExplorerPage;
Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt changesExt;
teamExplorerPage = teamExplorer.NavigateToPage(new Guid(pageGuid), null);
changesExt = teamExplorerPage.GetExtensibilityService(typeof(Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt)) as Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt;
My code is slightly different, since my code executes automatically when the Git Changes window is opened I don't need to do the teamExplorer.NavigateToPage() call. Instead I use teamExplorer.CurrentPage, which I can see in the debugger is actually the Git Changes page (GitPendingChangesPageVS is the type), so I should be making the same calls as in the example from the site. Here's my code in the Git Changes page's Loaded() function. Notice that I try to get the IChangesExt service 4 different ways, but all of them just return null.
public override void Loaded(object sender, SectionLoadedEventArgs e)
{
base.Loaded(sender, e);
// Find the Pending Changes extensibility service and save a handle to it.
var service = this.GetService<IChangesExt>();
var teamExplorer = this.GetService<ITeamExplorer>();
var service2 = teamExplorer.GetService(typeof(IChangesExt)) as IChangesExt;
var service3 = teamExplorer.CurrentPage.GetExtensibilityService(typeof(IChangesExt)) as IChangesExt;
var service4 = teamExplorer.CurrentPage.GetService<IChangesExt>();
...
}
Any ideas what I am doing wrong?
The extension is open source, so if you like you can download the source from here (make sure you get the GitInitialFunctionality branch) and take a look. The relevant code is in the GitChangesSection.cs file.
I have also posted this question on the MSDN forums in hopes that maybe someone who frequents those forums can help me.
Any suggestions are appreciated. Thanks!
I found the source of the problem. I just noticed that everything worked fine in VS 2013, but not in VS 2015. After checking my references I see that I had my VS 2015 project referencing the 2013 (v12.0) Microsoft.TeamFoundation.Git.Controls.dll, which is the assembly that contains the IChangesExt interface. I added the VS 2015 (v14.0) version of the dll to my solution and changed my VS 2015 project to reference it, and now it is working as expected :)