I am trying to link a changeset to an existing TFS workitem in C# with .NET client libraries for Azure DevOps Services (and TFS)
This is the code that I am using -
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;
}
}
but I get the same error every time...
VssServiceException: Unrecognized Resource link: Link Name: Merge changeset 377894 (workitem 174339) from Key2Dev322000 to TrunkSP Link Uri: vstfs:///_versionControl/Changeset/377986
Can anyone suggest what I am doing wrong?
I can reproduce the same issue when using the similar sample.
To solve this issue, you need to change the following points in your code:
1.The correct Changeset URL format: vstfs:///versionControl/Changeset/{ChangesetId}
. You need to remove the _
in the link.
2.The name field in the attributes should be the value Fixed in Changeset.
attributes = new { name = "Fixed in Changeset", LinkType = "Hyperlink" }
If you need to add comment, you need to add the comment field.
Update Sample:
We need to add comment field to attributes .
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", comment = $"{comment}", LinkType = "Hyperlink" }
}
});
// Send the update request
WorkItemTrackingHttpClient witClient = tfs.GetClient<WorkItemTrackingHttpClient>();
witClient.UpdateWorkItemAsync(patchDocument, workitemID).Wait();
}
catch (Exception)
{
throw;
}