以编程方式删除[永久] TFS工作项

时间:2011-10-03 10:24:07

标签: tfs tfs2010

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

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

2 个答案:

答案 0 :(得分:1)

Shai Raiten在博客中发表了关于here的博文,他使用DestroyWorkItems(ids)

建议您在实施过程中小心谨慎,因为这会严重破坏您的安装。有人可能会说,构建这样的工具会偏离最佳实践。

答案 1 :(得分:-1)

您还可以use PowerShell to bulk delete work items

  

在PowerShell文件中使用.ps1复制并粘贴脚本   扩展名),更新下面列表#4中提到的变量值   并从安装了witadmin工具的计算机上运行该命令   (视觉工作室安装后通常可用)。打开   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##