如何复制一个工作项目,其任务(How to copy a work item and its tas

2019-07-18 23:18发布

我想提出一个工作项的副本,它的所有的任务。

我使用这个版本的产品:11.0.50727.1我使用的Scrum 2.0模板项目

如果这是可能的,我该怎么办呢?

Answer 1:

您是否尝试过的Excel? 这是你最好的朋友做的工作项目质量编辑时。 您可以复制/粘贴的一些工作项目。 通过选择除ID列的所有列。 复制它们,然后将其粘贴在Excel中打开查询的底部。

您需要确保您使用的是基于树的查询,所有要复制的列是查询列的一部分。

的HTML类型的领域,虽然这种方式你可能会失去格式。

我很想知道你为什么会想他们的所有任务批量复制积压的产品项目,从混战角度来看,我实在不明白怎么会是有意义的。



Answer 2:

我的日期看这个问题是有点超过2岁。 Excel中不会造成对我的父母联系。 这里是我的PowerShell的解决方案:

if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
     Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")

# Connect to TFS and get Work Item Store.
$tfsCollectionUrl = "https://tfs.CORP.com/tfs/group"
$tfs = Get-TfsServer -name $tfsCollectionUrl
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")

$storyID = 15211    # ID of the story you want to copy.

$story = $ws.GetWorkItem($storyID)
Write-Host "Cloning User Story: " + $story.Title

#Clone User Story
$cloneStory = $story.Copy()
($story, $cloneStory )
$cloneStory.Title = "COPY : " + $story.Title

# cloneStory will not have links to all the tasks that were linked to the orginal story.
# cloneStory will have two links, one to the same "feature" that the orginal was linked to, and one to the story it was cloned from.
$cloneStory.Links

# cloneStory will have 0 for an ID, because it has not yet been saved.
$cloneStory.Id
#$cloneStory.Save()
# cloneStory will now have an ID.
$cloneStory.Id
$parentID = $cloneStory.Id  # Parent ID will be used to link new cloned tasks to this story.

$links = $story.Links

# Define a Link Type to be used in the loop.
$linkType = $ws.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]


foreach ( $link in $links )
{

    $itemID = $link.RelatedWorkItemId
    #$itemID

    $item = $ws.GetWorkItem($itemID)

    if ( ($item.Type).Name -eq "Task" )
    {
        $reportLine = "Cloning Task ID:{0} {1}" -f $itemId, $item.Title
        Write-Host $reportLine
        # Clone the Task
        # Create the Parent Link object
        # Add the Parent Link to Cloned Task
        # Save New Cloned Task

        $cloneTask = $item.Copy()
        $cloneTask.Title = "COPY : " + $item.Title
        $parentLink = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($linkType.ReverseEnd, $parentID)
        $cloneTask.WorkItemLinks.Add($parentLink)
        $cloneTask.save()
        $cloneTask
    }
    else
    {
        $reportLine = "Skipping: {0} is not a Task, it is a {1}" -f $item.Title, ($item.Type).Name
        Write-Host $reportLine
    }
}


文章来源: How to copy a work item and its tasks