如何访问“自定义"或使用 PowerShell 的非系统 TFS 工作项字段? [英] How to access "Custom" or non-System TFS workitem fields using PowerShell?

查看:35
本文介绍了如何访问“自定义"或使用 PowerShell 的非系统 TFS 工作项字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 PowerShell 从 TFS 提取信息时,我发现我可以获取标准字段,但不能获取自定义"字段.我不确定自定义是正确的术语,但例如,如果我查看 VS2008 中的流程编辑器并编辑工作项类型,则会出现如下所列的字段,包括名称、类型和引用名称:

When using PowerShell to extract information from TFS, I find that I can get at the standard fields but not "Custom" fields. I'm not sure custom is the correct term, but for example if I look at the Process Editor in VS2008 and edit the Work Item type, there are fields such as listed below, with Name, Type and RefName:

Title         String    System.Title
State         String    System.State
Rev           Integer   System.Rev
Changed By    String    System.ChangedBy

我可以使用 Get-TfsItemHistory 访问这些:

I can access these with Get-TfsItemHistory:

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -R 
  | Select -exp WorkItems | Format-Table Title, State, Rev, ChangedBy -Auto

到目前为止一切顺利.

但是,WorkItem 类型中还有一些其他字段,我称之为自定义"或非系统字段,例如:

However, there are also some other fields in the WorkItem type, which I'm calling "Custom" or non-System fields, e.g.:

Activated By  String    Microsoft.VSTS.Common.ActivatedBy
Resolved By   String    Microsoft.VSTS.Common.ResolvedBy

并且以下命令不检索数据,仅检索空格.

And the following command does not retrieve the data, just spaces.

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -R 
  | Select -exp WorkItems | Format-Table ActivatedBy, ResolvedBy -Auto

我也尝试过引号中的名称,完全限定的引用名称,但没有成功.您如何访问这些非系统"字段?

I've also tried the names in quotes, the fully qualified refname, but no luck. How do you access these "non-System" fields?

谢谢

波兹

更新:

从基思的回答中我可以得到我需要的字段:

From Keith's answer I can get the fields I need:

Get-TfsItemHistory "$/Hermes/Main" -Version "D01/12/10~" -Recurse `
  | Select ChangeSetId, Comment -exp WorkItems `
  | Select ChangeSetId, Comment, @{n='WI-Id'; e={$_.Id}}, Title -exp Fields `
  | Where {$_.ReferenceName -eq 'Microsoft.VSTS.Common.ResolvedBy'} `
  | Format-Table ChangesetId, Comment, WI-Id, Title, @{n='Resolved By'; e={$_.Value}} -Auto

注意事项:必须将 WorkItem 的 Id 重命名为 WI-Id,因为 Id 与 Field Id 不明确.重命名字段值属性会提供列标题名称而不是值".

Notes: Renaming of WorkItem's Id to WI-Id necessary because Id is ambiguous with Field Id. Renaming the Fields Value property gives a column heading name instead of "Value".

推荐答案

每个工作项中都有一个 Fields 集合属性,似乎包含所有工作项字段和值.像这样访问它:

There is a Fields collection property in each work item that appears to contain all the work item fields and values. Access it like so:

Get-TfsItemHistory . -r -vers "D12/14/2010~" | 
    Where {$_.WorkItems.count -gt 0} | Select -Expand workitems | 
    Select @{n='WIT-Id';e={$_.Id}},Title -Expand Fields | 
    Where {$_.ReferenceName -eq 'Microsoft.VSTS.Common.ActivatedBy'} | 
    Format-Table Value,WIT-Id,Title -auto

这篇关于如何访问“自定义"或使用 PowerShell 的非系统 TFS 工作项字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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