user4380125
user4380125

Reputation: 95

How to link a TFS workitem to another using command line

How does one link an existing TFS work item to another using in command prompt. Is there a command line option for this in TFS. I know I can use tfpt.exe to create a workitem or modify it, but I cannot find an option to link a workitem to another.

Upvotes: 4

Views: 1048

Answers (1)

demokritos
demokritos

Reputation: 1446

Assuming you will use "Related" link type, this should link your work items..

[string]$tfsURL="http://tfs:8080/tfs"
[psobject] $tfs=[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsURL)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
$wit=$tfs.Getservice([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

$item1=$tfs.WIT.GetWorkItem(1)
$item1.Open()
$item2=$tfs.WIT.GetWorkItem(3)
$linkType=$tfs.WIT.WorkItemLinkTypes.Item("System.LinkTypes.Related")
$witLink=New-Object Microsoft.TeamFoundation.WorkitemTracking.Client.WorkitemLink($linkType.ForwardEnd,$item2.Id)
$item1.WorkItemLinks.Add($witLink)
$item1.Validate()
$item1.Save()
$item1.Close()

Upvotes: 2

Related Questions