TFS - VS扩展:添加工作项通过API挂起的更改 [英] TFS - VS Extension: Add work item to pending changes via API

查看:602
本文介绍了TFS - VS扩展:添加工作项通过API挂起的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个VS扩展/插件和我需要与挂起的更改工作项目(不触发入住)相关联。

I am currently working on a VS extension / add-in and I need to associate work items with the pending changes (without triggering a check-in).

寻找一些小时后我无法找到一个方法通过API来实现这一目标。我发现一个工作项挂起更改关联的唯一方式是Workspace.CheckIn(),这也将触发入住..

After searching for some hours I couldn't find a way to accomplish this via the API. The only way I found to associate a work item to the pending changes is Workspace.CheckIn() which also would trigger the check-in..

难道我错过了什么?或者,这是真的不可能?

Do I miss something? Or is this really not possible?

推荐答案

我已经提供了下面的示例代码,需要注意的是,我没有尝试过这样的代码,但现在看来,这只能通过一些反思。这是因为API中实现这个的公共方法。随着VS2012 / 13新的团队资源管理器窗口中,您将理想扩展团队资源管理器提供您要的功能。有 MSDN上扩展它的一些例子。

I have provided the sample code below, Note that, I have not tried this code, but it seems it is only possible through some reflection as there is no public method to achieve this in the API. With the new Team Explorer window in VS2012/13, you would ideally extend the Team Explorer to provide the functionality you intend to. There are some examples of extending it on MSDN.

下面的代码,获得服务提供者的实例。你可以在的IServiceProvider 对象,通过你的包实例。一旦你得到它,你需要调用AddWorkItemById方法,它是私有的 - 检查方法定义的此处

The code below, get the service provider instance. You can get the IServiceProvider object, through your package instance. Once you get it, you need to call AddWorkItemById method which is private - Check the method definition here.

int id = workItemId;
IPendingChangesExt service = serviceProvider.GetService<IPendingChangesExt>();
FieldInfo field = service.GetType().GetField("m_workItemsSection", BindingFlags.Instance | BindingFlags.NonPublic);
Type fieldType = field.FieldType;
object value = field.GetValue(service);
MethodInfo method = fieldType.GetMethod("AddWorkItemById", BindingFlags.Instance | BindingFlags.NonPublic);
object[] objArray = new object[] { id };
method.Invoke(value, objArray);

这篇关于TFS - VS扩展:添加工作项通过API挂起的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆