无法使用 TFS API 将变更集链接到现有工作项

问题描述 投票:0回答:1

我正在尝试使用 Azure DevOps Services(和 TFS)的 .NET 客户端库将变更集链接到 C# 中的现有 TFS 工作项

这是我正在使用的代码-

     public void CreateChangesetLinkAsync(int workitemID, int ChangesetId, string comment)
     {
         string changesetUrl = $"vstfs:///_versionControl/Changeset/{ChangesetId}";

         try
         {


            // Define the update operations using a JsonPatchDocument
             JsonPatchDocument patchDocument = new JsonPatchDocument();
             patchDocument.Add(new JsonPatchOperation()
             {
                 Operation = Operation.Add,
                 Path = "/relations/-",
                 Value = new
                 {
                     rel = "ArtifactLink",
                     url =$"{changesetUrl}",
                     attributes = new {name = $"{comment}", LinkType = "Hyperlink" }

             }
             });

             // Send the update request
             WorkItemTrackingHttpClient witClient = tfs.GetClient<WorkItemTrackingHttpClient>();
             witClient.UpdateWorkItemAsync(patchDocument, workitemID).Wait();
         }
         catch (Exception)
         {

             throw;
         }


     }

但是我每次都会遇到同样的错误...

VssServiceException:无法识别的资源链接:链接名称:将变更集 377894(工作项 174339)从 Key2Dev322000 合并到 TrunkSP 链接 Uri:vstfs:///_versionControl/Changeset/377986

任何人都可以建议我做错了什么吗?

c# azure-devops tfs tfvc
1个回答
0
投票

使用类似示例时我可以重现相同的问题。

要解决此问题,您需要更改代码中的以下几点:

1.正确的变更集 URL 格式:

vstfs:///versionControl/Changeset/{ChangesetId}
。您需要删除链接中的
_

2.属性中的名称字段应该是值在Changeset中固定

attributes = new { name = "Fixed in Changeset", LinkType = "Hyperlink" }

参考此示例:

 public void CreateChangesetLinkAsync(int workitemID, int ChangesetId, string comment)
 {
     string changesetUrl = $"vstfs:///versionControl/Changeset/{ChangesetId}";

     try
     {


        // Define the update operations using a JsonPatchDocument
         JsonPatchDocument patchDocument = new JsonPatchDocument();
         patchDocument.Add(new JsonPatchOperation()
         {
             Operation = Operation.Add,
             Path = "/relations/-",
             Value = new
             {
                 rel = "ArtifactLink",
                 url =$"{changesetUrl}",
                 attributes = new {name = "Fixed in Changeset", LinkType = "Hyperlink" }

         }
         });

         // Send the update request
         WorkItemTrackingHttpClient witClient = tfs.GetClient<WorkItemTrackingHttpClient>();
         witClient.UpdateWorkItemAsync(patchDocument, workitemID).Wait();
     }
     catch (Exception)
     {

         throw;
     }
© www.soinside.com 2019 - 2024. All rights reserved.