如何将文本文件或 xml 内容添加到 Powershell 中的 TFS WorkItem 描述?

How to add a text file or xml content to a TFS WorkItem description in Powershell?

我想使用 powershell 在 TFS Workitem 中添加一些描述。 我写了以下代码:

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

    # Get TFS server and query from WIQ file
        [xml]$WiqlXML = Get-Content $WiqPath
        [String]$TFSservername = $WiqlXML | % {$_.WorkItemQuery.TeamFoundationServer} 
        [String]$queryString = $WiqlXML | % {$_.WorkItemQuery.Wiql}
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSservername)

    # Get workitem collection from TFS Project
    $ws = $teamProjectCollection.GetService([type][Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
    $wis = $ws.Query($queryString);

    [Net.WebClient] $request =  New-Object Net.WebClient
    $request.UseDefaultCredentials = $true
foreach($wi in $wis)
{
    $wi.Description += "`r`n========================================================"
    $wi.Description += "<xml>content</xml>"
}

但是,仅在工作项中 ================================== ====================== 添加

您的所有内容都已添加,但由于它是一个 HTML 框,因此不会呈现并消失。

您需要 HTML 对您的 xml 进行编码,然后再将其添加到描述字段。