C# TFS在讨论中添加评论
我正在从LeanKit迁移卡片,我需要在TFS上的卡片中为讨论添加注释。 如何以其他用户的身份向WorkItem添加编程注释? 可能吗? 我发现仅以登录用户的身份按历史属性添加注释C# TFS在讨论中添加评论,c#,.net,tfs,comments,C#,.net,Tfs,Comments,我正在从LeanKit迁移卡片,我需要在TFS上的卡片中为讨论添加注释。 如何以其他用户的身份向WorkItem添加编程注释? 可能吗? 我发现仅以登录用户的身份按历史属性添加注释 谢谢 只有在您使用其他用户的凭据登录时,您才能作为其他用户向讨论中添加评论: NetworkCredential cred = new NetworkCredential("anotherUserName", "password"); TfsTeamProjectCollection _tfs = new TfsTe
谢谢 只有在您使用其他用户的凭据登录时,您才能作为其他用户向讨论中添加评论:
NetworkCredential cred = new NetworkCredential("anotherUserName", "password");
TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(new Uri("serverUrl"), cred);
_tfs.EnsureAuthenticated();
在您像其他用户一样进行身份验证后,将文本添加到历史记录字段,您将在讨论中看到作为登录的其他用户的文本。默认情况下,我们只能添加登录用户的评论 但是,您可以使用REST API将注释添加到与其他用户的讨论中,以更新
系统的值。通过启用旁路规则的字段进行更改:
以下样本供您参考:
Param(
[string]$baseurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "ProjectName",
[string]$workitemID = "26",
[string]$user = "username",
[string]$token = "token/Password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
write-host $WorkitemType
function CreateJsonBody
{
$value = @"
[
{
"op": "add",
"path": "/fields/System.History",
"value": "Comment here"
},
{
"op": "add",
"path": "/fields/System.ChangedBy",
"value": "user@oxxx.com"
}
]
"@
return $value
}
$json = CreateJsonBody
$uri = "$baseurl/$($projectName)/_apis/wit/workitems/$($workitemID)?bypassRules=true&api-version=2.2"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
“价值”:user@oxxx.com“可以是其他用户的有效用户id(guid)或用户电子邮件