TFS rest API-创建工作项

时间:2017-02-28 13:46:01

标签: c# tfs

我正在尝试使用Microsoft.TeamFoundationService.Client api创建工作项,但每当我尝试创建工作项时,它都会失败并显示错误

  

新工作项更新必须指定Area和Iteration节点ID。

到目前为止,我有以下内容:

var connection = new VssConnection(baseUrl, vssBasicCredential);
var witClient = connection.GetClient<WorkItemTrackingHttpClient>();

var patchDocument = new JsonPatchDocument();
patchDocument.Add(new JsonPatchOperation
{
  Operation = Operation.Add,
  Path = "/Fields/System.Title",
  Value = title
});

...
var newlyCreatedUserStory = witClient.CreateWorkItemAsync(patchDocument,
                                                          testProject.Id,
                                                          "User Story").Result;

此时抛出异常。我也尝试添加Area和Interation节点的值:

        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.AreaId",
            Value = parentWorkItem.Fields["System.AreaId"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.AreaPath",
            Value = parentWorkItem.Fields["System.AreaPath"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.TeamProject",
            Value = parentWorkItem.Fields["System.TeamProject"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.NodeName",
            Value = parentWorkItem.Fields["System.NodeName"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.AreaLevel1",
            Value = parentWorkItem.Fields["System.AreaLevel1"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.IterationId",
            Value = parentWorkItem.Fields["System.IterationId"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.IterationPath",
            Value = parentWorkItem.Fields["System.IterationPath"].ToString()
        });
        patchDocument.Add(new JsonPatchOperation
        {
            Operation = Operation.Add,
            Path = "/Fields/System.IterationLevel1",
            Value = parentWorkItem.Fields["System.IterationLevel1"].ToString()
        });

有什么想法吗?提前谢谢。

2 个答案:

答案 0 :(得分:2)

如果您打算使用TFS2015。建议你不要用VSTS测试。两者之间可能存在一些差异,例如API版本。

据我所知,创建工作项不需要指定Area和Iteration节点ID。只需要标题。您可以参考官方教程的示例代码:Create a work item

由于您使用的是预览库,您还可以尝试使用稳定版本,例如Microsoft Team Foundation Server Client 14.102.0

还添加了一个类似的问题供您参考:TFS2015 REST API Library: Create a new Work Item

答案 1 :(得分:1)

更改

Path = "/Fields/System.Title"

Path = "/fields/System.Title"

是我的把戏。