批量删除TFS工作项链接 [英] Removing TFS Work Item Links in Bulk

查看:138
本文介绍了批量删除TFS工作项链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个powershell脚本,可以让我成功创建工作项目相关链接。该脚本逐行遍历CSV文件,从第一列中读取工作项ID 然后在第二列中创建带有工作项
ID的链接。该脚本是一种享受,因为我可以在几秒钟内链接数百个工作项。

I have a powershell script which enables me to create work item Related links successfully. The script iterates through a CSV file and row by row, reads a work item ID from the first column and then creates a link with the work item ID in the second column. The script works a treat, as I can link hundreds of work items within seconds.

我现在迫切需要能够扭转这种创建工作项链接的趋势。我之所以能够做的是使用同一个CSV文件中的数据删除链接,但是所有尝试调整代码来实现这一点都是
徒劳无功,包括甚至更改方法$ childWIT .WorkItemLinks.Add to $ childWIT.WorkItemLinks.Remove。

I now have an urgent need to be able to reverse this trend of creating the work item links. What I'd therefore like to be able to do is remove the links using the data from the same CSV file, however all attempts to tweak the code to achieve this has been futile, including even changing the method $childWIT.WorkItemLinks.Add to $childWIT.WorkItemLinks.Remove.

任何人都知道我怎么能做到这一点?

Anyone have any idea how I could achieve this?

以下是代码主要部分的片段,用于链接:

Below is a snippet of the main section of the code which does the linking:

$ list = Import-Csv $ csvFile

foreach($ list in $ list)

{

   $ childWIT = $ wis.GetWorkItem($ map.Child)



   Write-Host"从父创建链接:$($ map.Parent)到Child:$($ map.Child)" -ForegroundColor Green



   $ hierarchyLink = $ wis.WorkItemLinkTypes [[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames] :: Hierarchy]

   $ link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($ hierarchyLink.ReverseEnd,$ map.Parent)   


   $ childWIT.WorkItemLinks.Add($ link)

  尝试

   {

      $ childWIT.Save();

     写主机"创建链接" -ForegroundColor DarkGreen

   }

  抓住

   {

     写入错误"无法保存工作项目$ map.Child"

     写错误$ _

   }

}

$list = Import-Csv $csvFile
foreach($map in $list)
{
   $childWIT = $wis.GetWorkItem($map.Child)

   Write-Host "Creating Link from Parent:$($map.Parent) to Child:$($map.Child)" -ForegroundColor Green

   $hierarchyLink = $wis.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
   $link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($hierarchyLink.ReverseEnd, $map.Parent)   
   $childWIT.WorkItemLinks.Add($link)
   try
   {
      $childWIT.Save();
      Write-Host "Link created" -ForegroundColor DarkGreen
   }
   catch
   {
      Write-Error "Could not save work item $map.Child"
      Write-Error $_
   }
}

推荐答案

您好ReggM,

Hi ReggM,

请迭代目标工作项对象(foreach)的WorkItemLinks集合,然后调用Remove方法删除当前WorkItemLink。

Please iterate WorkItemLinks collection of target workitem object (foreach), then call Remove method to remove current WorkItemLink.

问候

Starain


这篇关于批量删除TFS工作项链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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