如何以编程方式更新自定义 TFS 字段 [英] How to update a custom TFS field programmatically

查看:22
本文介绍了如何以编程方式更新自定义 TFS 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个自定义构建过程(不使用 MS Build),在此过程中,我将一个假"构建添加到全局构建列表中.我这样做的原因是,您可以为给定的工作项(在构建中找到)选择构建.我们有一个自定义字段,包括构建,旨在显示修复了该工作项的构建.我无法弄清楚如何以编程方式更新此字段.这个想法是我将有一个小应用程序来执行此操作,我将在构建过程中调用它,查找自上次构建以来的所有工作项,然后更新这些工作项的字段.有什么想法吗?

We have a custom build process (not using MS Build) and during that process I am adding a "fake" build to the global builds list. The reason I am doing that is so that you can select the build for a given work item (found in build). We have a custom field, build included, which is intended to show which build that work item was fixed in. I am having trouble figuring out how to update this field programmatically. The idea is I will have a small app that does this that I will call during the build process, finding all work items since the last build, then updating the field for those work items. Any ideas?

推荐答案

这样的事情应该对你有用:

Something like this should work for you:

public void UpdateTFSValue(string tfsServerUrl, string fieldToUpdate, 
   string valueToUpdateTo, int workItemID)
{   
    // Connect to the TFS Server
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsUri));
    // Connect to the store of work items.
    _store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
    // Grab the work item we want to update
    WorkItem workItem = _store.GetWorkItem(workItemId);
    // Open it up for editing.  (Sometimes PartialOpen() works too and takes less time.)
    workItem.Open();
    // Update the field.
    workItem.Fields[fieldToUpdate] = valueToUpdateTo;
    // Save your changes.  If there is a constraint on the field and your value does not 
    // meet it then this save will fail. (Throw an exception.)  I leave that to you to
    // deal with as you see fit.
    workItem.Save();    
}

调用它的一个例子是:

UpdateTFSValue("http://tfs2010dev:8080/tfs", "Integration Build", "Build Name", 1234);

变量 fieldToUpdate 应该是字段的名称,而不是引用名称(即 Integration Build,而不是 Microsoft.VSTS.Build.IntegrationBuildem>)

The variable fieldToUpdate should be the name of the field, not the refname (ie. Integration Build, not Microsoft.VSTS.Build.IntegrationBuild)

您可能可以使用 PartialOpen(),但我不确定.

You could probably get away with using PartialOpen(), but I am not sure.

您可能需要将 Microsoft.TeamFoundation.Client 添加到您的项目中.(也许 Microsoft.TeamFoundation.Common)

You will probably need to add Microsoft.TeamFoundation.Client to your project. (And maybe Microsoft.TeamFoundation.Common)

这篇关于如何以编程方式更新自定义 TFS 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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