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.
Asked
Active
Viewed 1,007 times
4
-
This is an old question from 2011 https://social.msdn.microsoft.com/Forums/en-US/4d32342a-ff23-4752-91b7-b34567fe26be/how-to-link-work-items-together-with-tfpt?forum=tfspowertools but it says that linking workitems is not supported in tfpt.exe. – nemesv Dec 20 '14 at 07:36
-
1It's relatively easy to create a custom command line tool or Powershell script using the TFS CLient Object Model. Would that work for you as well? – jessehouwing Dec 20 '14 at 11:45
-
1Yes, that would work for me if I could find out how to create a custom command line tool. – user4380125 Dec 22 '14 at 17:32
1 Answers
2
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()

demokritos
- 1,416
- 2
- 12
- 34