【发布时间】:2014-02-01 06:07:53
【问题描述】:
我们有一个基本处理 TFS 操作的 Visual Studio 2010 插件。当有人签入一些文件时,它会向相应的人发送电子邮件,并对其他一些本地 MSSQL 数据库和类似情况进行签出和合并。
它与 TFS2005 一起工作了很长时间,但最近我们将 tfs 从 2005 升级到 2010,然后升级到 2013。
现在我们的插件不起作用。简单地说,VersionControlServer 的事件没有触发。不管我怎么做,谷歌搜索我找不到任何解决方案。我们认为 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 成功了。
谢谢大家的支持。
更新 2 无论我说多少“谢谢”,对于 Carlos Quintero 的帮助都是不够的。 再次感谢我的好人!
【问题讨论】:
-
这看起来是正确的。例如,我看不到执行 get 或创建新的挂起更改的代码。你确定你有相同的
VersionControlServer对象吗?你能发布一个更完整的代码示例吗? -
您好@EdwardThomson,没有用于获取或创建新的挂起更改的代码。用户交互应该触发这些事件,例如,如果在插件菜单中启用了插件,当用户尝试签出某个文件时;我需要触发这些事件,因此应该弹出一些窗口表单供用户选择相关问题进行编辑。如果你想看更多,我想我可以发布更多的代码......顺便谢谢你。 PS:此源代码与 TFS2005 完美配合。
-
顺便问一下,.net 框架可能是导致此问题的原因吗? tfs 升级后,我也将解决方案项目迁移到 .net 框架 4。 tfs 文件夹中是否有任何日志文件或其他内容会显示错误或任何内容?
-
添加了您的解决方案作为答案。
-
什么是_applicationObject?
标签: c# visual-studio-2010 tfs