我们有一个自定义构建过程(不使用MS Build),在此过程中我将"假"构建添加到全局构建列表中.我这样做的原因是您可以选择给定工作项的构建(在构建中找到).我们有一个自定义字段,包括构建,用于显示修复了哪个工作项目.我无法确定如何以编程方式更新此字段.我的想法是,我将有一个小应用程序执行此操作,我将在构建过程中调用,查找自上次构建以来的所有工作项,然后更新这些工作项的字段.有任何想法吗?
Vac*_*ano 13
这样的事情对你有用:
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();
}
Run Code Online (Sandbox Code Playgroud)
调用它的一个例子是:
UpdateTFSValue("http://tfs2010dev:8080/tfs", "Integration Build", "Build Name", 1234);
Run Code Online (Sandbox Code Playgroud)
变量fieldToUpdate应该是字段的名称,而不是refname(即Integration Build,而不是Microsoft.VSTS.Build.IntegrationBuild)
你可能可以使用PartialOpen(),但我不确定.
您可能需要添加Microsoft.TeamFoundation.Client到项目中.(也许Microsoft.TeamFoundation.Common)
这在 TFS 2012 中已经改变,基本上你必须添加 workItem.Fields[fieldToUpdate] .Value
@Vaccano 所写内容的更新版本。
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].Value = 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();
}
Run Code Online (Sandbox Code Playgroud)