我正在尝试将Git支持添加到我的Visual Studio 2015扩展中
Diff All Files
。我在TFVC团队资源管理器页面上的一切都正常工作,现在我正在尝试在Git更改和Git历史页面上显示我的扩展名。为了能够检测GitChanges页面上的挂起更改,我需要获取IChangesNext服务的句柄。
This page shows how to do it
,但出于某种原因,它对我不起作用;我总是只返回一个空值,而不是期望的IChangesNext实例。
以下是该网站的相关代码片段:
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;
我的代码略有不同,因为我的代码在打开GitChanges窗口时自动执行,所以我不需要使用teamExplorer。NavigateToPage()调用。相反,我使用teamExplorer。我可以在调试器中看到的CurrentPage实际上是GitChanges页面(GitPendingChangesPageVS是类型),因此我应该在站点中进行与示例中相同的调用。这是我在GitChanges页面的Loaded()函数中的代码。请注意,我尝试以4种不同的方式获取IChangesExt服务,但它们都返回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>();
...
}
知道我做错了什么吗?
该扩展是开源的,因此如果您愿意,可以
download the source from here
(确保获得GitInitialFunctional分支)并查看。相关代码在GitChangesSection中。cs文件。
我还发布了
this question on the MSDN forums
希望经常参加这些论坛的人能帮助我。
欢迎提出任何建议。谢谢