【问题标题】:Programatically delete [permenantly] a TFS work item以编程方式[永久]删除 TFS 工作项
【发布时间】:2011-11-29 19:53:51
【问题描述】:

虽然我知道有一个命令行工具可以永久删除 TFS 工作项。 (例如How to delete Work Item from Team Foundation Server

是否有人能够使用 TFS 2010 API DLL 以编程方式实现相同的操作?

【问题讨论】:

    标签: tfs tfs-sdk


    【解决方案1】:

    Shai Raiten 曾在博客上写过这个here,他在其中使用了DestroyWorkItems(ids)

    建议您在实施过程中格外小心,因为这会严重扰乱您的安装。有人可能会争辩说,构建这样一个工具偏离了最佳实践。

    【讨论】:

      【解决方案2】:

      你也可以use PowerShell to bulk delete work items:

      将以下脚本复制并粘贴到 PowerShell 文件中(使用 .ps1 扩展名),更新下面列表 #4 中提到的变量值 并从安装了 witadmin 工具的机器上运行命令 (一般在visual studio安装后可用)。打开 PowerShell 命令窗口并执行脚本。 注意:在脚本下运行的帐户应具有团队基金会管理员或集合管理员访问权限。

      ########TFS Work Items Bulk Destroy Automation Script##########
      #Notes:
      #1) This script requires to setup file/folder path, validate the file/folders path before running the script
      #2) start the powershell window as Administrator and run the script
      #3) This script requires share and admin access on the destination server, make sure your account or the account under which script is
      #    executing is member of admin group on the destination server
      #4) Update following:
      #   4.1: $CollectionURL
      #   4.2: $WitAdmin tool location
              # For VS 2015, Default location is C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
              # For VS 2013, Default location is C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
      #   4.3: $WI_List
      #   4.4: $logfile
      ####################
      
      $CollectionURL = "http://tfs:8080/tfs/CollectionName"
      $WitAdminLocation = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
      $WI_List =  Get-Content "C:\WI_List.txt"
      $logfile="C:\log.txt"
      $ExecutionStartTime = Get-Date
      $WICount = 0
      "## Starting WI Destroy @ $ExecutionStartTime ##"| Out-File $logfile -Append
      "Collection URL: $CollectionURL" | Out-File $logfile -Append
      foreach ($WIID in $WI_List)
          {
              CD $WitAdminLocation
              .\witadmin destroywi /collection:$CollectionURL /id:$WIID /noprompt
              "WI ID: $WIID Destroyed" | Out-File $logfile -Append
              $WICount = $WICount + 1
              Write-Host "$WICount Work Items Deleted"
          }
      
      $ExecutionEndTime = Get-Date
      "## WI Destroy Command Completed @ $ExecutionEndTime ##"| Out-File $logfile -Append
      
      $TotalExecutionTime = $ExecutionEndTime - $ExecutionStartTime
      
      "Total Work Items Deleted: $WICount"   | Out-File $logfile -Append
      
      " Total Execution Time: $TotalExecutionTime"  | Out-File $logfile -Append
      
      ##End of script##
      

      【讨论】:

      • 把相关信息放到帖子里。
      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 2011-02-20
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      相关资源
      最近更新 更多