How to link a TFS workitem to another using command line

1k views Asked by At

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.

1

There are 1 answers

0
demokritos On

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()