无法消费TFS 2013事件。在C#中,事件根本没有触发。

4
我们有一个 Visual Studio 2010 插件,主要处理 TFS 操作。当有人提交文件时,它会发送电子邮件给相应的人,并对一些其他本地 MSSQL 数据库进行一些更改,类似于检查和合并的情况。
长期以来,它与 TFS2005 配合工作良好,但最近我们将 tfs 从 2005 升级到了 2010,然后是 2013。
现在我们的插件不起作用了。简单地说,VersionControlServer 的事件没有触发。无论我如何尝试,Google 也找不到任何解决方案。我们认为 TFS2013 处理这些问题的方式不同,但这个插件对我们的工作至关重要,我们不想回滚到 TFS2005。
下面是我的示例代码;
public void invoke()
{
    // Get a reference to our Team Foundation Server.
    var tpc = new TfsTeamProjectCollection(new Uri(_tfsURL));

    // Get a reference to Version Control.
    var versionControl = tpc.GetService<VersionControlServer>();

    // Listen for the Source Control events.
    versionControl.Getting += new GettingEventHandler(versionControl_Getting);
    versionControl.BeforeCheckinPendingChange += new ProcessingChangeEventHandler(versionControl_BeforeCheckinPendingChange);
    versionControl.NewPendingChange += new PendingChangeEventHandler(versionControl_NewPendingChange);
}

private void versionControl_NewPendingChange(object sender, PendingChangeEventArgs e)
{
     //some logic here
}

private void versionControl_BeforeCheckinPendingChange(object sender, ProcessingChangeEventArgs e)
{
     //some logic here
}

private void versionControl_Getting(object sender, GettingEventArgs e)
{
     //some logic here
}

有什么可能导致这个问题吗?

提前感谢你的帮助。

更新:我已经找到了解决方案。我将上面的代码块改成了以下方式;

        //+     _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt")   {Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt} dynamic {Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt}
        var tfsExt = (TeamFoundationServerExt)_applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");

        //if ((tfsExt == null) || (tfsExt.ActiveProjectContext == null) || (tfsExt.ActiveProjectContext.DomainUri == null) || (tfsExt.ActiveProjectContext.ProjectUri == null)) { MessageBox.Show("Please Connect to TFS first and select a Team Project"); }
        //else { MessageBox.Show("Connected to:" + tfsExt.ActiveProjectContext.ProjectName); }

        var vsExt = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

        //vcs = vsExt.Explorer.Workspace.VersionControlServer;
        vcs = vsExt.SolutionWorkspace.VersionControlServer;

        vcs.OperationStarting += new OperationEventHandler(this.OperationHandler);
        vcs.UndonePendingChange += new PendingChangeEventHandler(this.UndoChange);
        vcs.Getting += new GettingEventHandler(this.GetHandler);
        vcs.NewPendingChange += new PendingChangeEventHandler(this.NewPendingChange);
        vcs.BeforeCheckinPendingChange += new ProcessingChangeEventHandler(this.BeforeCheckinPendingChange);
        vcs.CommitCheckin += new CommitCheckinEventHandler(this.CommitCheckin);
        vcs.Conflict += new ConflictEventHandler(this.Conflict);
        vcs.Merging += new MergeEventHandler(this.Merging);
        vcs.AfterWorkItemsUpdated += new AfterWorkItemsUpdatedEventHandler(this.AfterWorkItemsUpdated);
        vcs.BeforeWorkItemsUpdate += new BeforeWorkItemsUpdateEventHandler(this.BeforeWorkItemsUpdate);
        vcs.OperationFinished += new OperationEventHandler(this.OperationFinished);
        vcs.UpdatedWorkspace += new WorkspaceEventHandler(this.UpdatedWorkspace);
        vcs.WorkItemUpdated += new WorkItemUpdatedEventHandler(this.WorkItemUpdated);

通过使用Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt,我们成功地解决了问题。感谢大家的支持。

此外,Daniel在这里提供了详细说明:http://social.msdn.microsoft.com/Forums/vstudio/en-US/e1433eb6-6418-46ed-8e18-7a9878e416c1/visual-studio-addin-to-intercept-checkin-checkout-and-other-tfs-2010-version-control-events?forum=tfsversioncontrol

更新2 不管我说多少次“谢谢”,都不足以表达Carlos Quintero所提供的帮助之深刻。再次感谢!


这看起来是正确的。例如,我没有看到执行get操作或创建新挂起更改的代码。你确定你有相同的“VersionControlServer”对象吗?你能发一个更完整的代码示例吗? - Edward Thomson
你好@EdwardThomson,没有获取或创建新挂起更改的代码。用户交互应该触发这些事件,例如如果插件在插件菜单中启用,当用户尝试检出某个文件时; 我需要这些事件触发,并且结果会弹出一些窗体供用户选择相关问题进行编辑。如果您想看更多,我可以发布更多代码...顺便说一句,谢谢。 PS:此源代码在TFS2005上完美运行。 - Atesoglu
顺便问一下,.net框架可能是这个问题的原因吗?在TFS升级后,我也将解决方案项目迁移到了.net框架4。在TFS文件夹中是否有任何日志文件或其他东西可以显示错误或其他内容? - Atesoglu
将您的解决方案添加为答案。 - jessehouwing
什么是_applicationObject? - Jesse
1个回答

0
我已经找到了解决方案。不再使用上面的代码块,而是将其更改为:
//+     _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt")   {Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt} dynamic {Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt}
var tfsExt = (TeamFoundationServerExt)_applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");

//if ((tfsExt == null) || (tfsExt.ActiveProjectContext == null) || (tfsExt.ActiveProjectContext.DomainUri == null) || (tfsExt.ActiveProjectContext.ProjectUri == null)) { MessageBox.Show("Please Connect to TFS first and select a Team Project"); }
//else { MessageBox.Show("Connected to:" + tfsExt.ActiveProjectContext.ProjectName); }

var vsExt = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

//vcs = vsExt.Explorer.Workspace.VersionControlServer;
vcs = vsExt.SolutionWorkspace.VersionControlServer;

vcs.OperationStarting += new OperationEventHandler(this.OperationHandler);
vcs.UndonePendingChange += new PendingChangeEventHandler(this.UndoChange);
vcs.Getting += new GettingEventHandler(this.GetHandler);
vcs.NewPendingChange += new PendingChangeEventHandler(this.NewPendingChange);
vcs.BeforeCheckinPendingChange += new ProcessingChangeEventHandler(this.BeforeCheckinPendingChange);
vcs.CommitCheckin += new CommitCheckinEventHandler(this.CommitCheckin);
vcs.Conflict += new ConflictEventHandler(this.Conflict);
vcs.Merging += new MergeEventHandler(this.Merging);
vcs.AfterWorkItemsUpdated += new AfterWorkItemsUpdatedEventHandler(this.AfterWorkItemsUpdated);
vcs.BeforeWorkItemsUpdate += new BeforeWorkItemsUpdateEventHandler(this.BeforeWorkItemsUpdate);
vcs.OperationFinished += new OperationEventHandler(this.OperationFinished);
vcs.UpdatedWorkspace += new WorkspaceEventHandler(this.UpdatedWorkspace);
vcs.WorkItemUpdated += new WorkItemUpdatedEventHandler(this.WorkItemUpdated);

而且Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt已经解决了这个问题。

此外Daniel在这里有一个描述;


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接