简体   繁体   English

如何以编程方式关闭TFS工作项

[英]How to programmatically close a TFS work item

I am attempting to import items from a legacy issue tracking system stored in an Excel sheet into Team Foundation Server. 我试图将存储在Excel工作表中的旧版问题跟踪系统中的项目导入Team Foundation Server。 I loop through the rows of the Excel file successfully, and I can create new work items, but they are always in the Proposed state. 我成功地循环浏览了Excel文件的行,并且可以创建新的工作项,但是它们始终处于“建议”状态。 If I attempt to change the state to Closed, then call the Validate method for the work item, I receive a validation error on the State property - InvalidListValue{4}. 如果我尝试将状态更改为“已关闭”,然后为工作项调用Validate方法,则会收到State属性-InvalidListValue {4}上的验证错误。

    Dim MyProj As Project = store.Projects("MyProject")
    Dim WIT As WorkItemType = MyProj.WorkItemTypes("Task")
    Dim WorkItem As WorkItem = WIT.NewWorkItem()

    WorkItem.Title = Title
    WorkItem.Description = Description
    WorkItem.History = History
    WorkItem.State = "Closed"
    WorkItem.Fields("Assigned To").Value = AssignedTo
    WorkItem.Fields("Priority").Value = Priority
    WorkItem.Fields("Closed By").Value = ClosedBy

I have also tried the code below, attempting to save the work item, change the State to closed, and save it again, but this doesn't appear to work either - the State is still Proposed when I open it up under the My Work Items TFS query: 我还尝试了下面的代码,尝试保存工作项,将状态更改为已关闭,然后再次保存,但这似乎也不起作用-当我在“我的工作”下打开它时,状态仍然是拟议的物品TFS查询:

        WorkItem.Save()

        WorkItem.State = "Closed"
        WorkItem.Fields("Closed By").Value = ClosedBy
        WorkItem.Save()

Has anyone else tried such a thing and succeeded, or have ideas for doing it? 有没有其他人尝试过这样的事情并且成功了,或者对此有想法? Oh, and this is a CMMI task that I am trying to create and close. 哦,这是我正在尝试创建和关闭的CMMI任务。 I wonder if I'm trying to skip over certain activities required by CMMI, but I'm new to this, and that's just a guess. 我想知道我是否要跳过CMMI要求的某些活动,但是我对此并不陌生,这只是一个猜测。

I figured out how to create and close a TFS CMMI task programmatically. 我想出了如何以编程方式创建和关闭TFS CMMI任务。 The key was to go through the CMMI process, which can be found at http://msdn.microsoft.com/en-us/library/bb668962.aspx , changing the State propery and saving the WorkItem after each change. 关键是要执行CMMI流程,该流程可以在http://msdn.microsoft.com/zh-cn/library/bb668962.aspx中找到,更改状态属性并在每次更改后保存WorkItem。

        ... WorkItem creation tasks
        WorkItem.Fields("Assigned To").Value = AssignedTo
        WorkItem.Fields("Priority").Value = Priority

        'This first Save creates a WorkItem in the Proposed state'
        WorkItem.Save()

        WorkItem.State = "Active"
        Errors = WorkItem.Validate()
        WorkItem.Save()

        WorkItem.State = "Resolved"
        WorkItem.Fields("Resolved By").Value = ClosedBy
        WorkItem.Fields("Resolved Reason").Value = "Just because"
        Errors = WorkItem.Validate()
        WorkItem.Save()

        WorkItem.State = "Closed"
        WorkItem.Fields("Closed By").Value = ClosedBy
        Errors = WorkItem.Validate()
        WorkItem.Save()

You should use the TFS Integration Platform for this. 您应该为此使用TFS集成平台。

http://tfsintegration.codeplex.com/ http://tfsintegration.codeplex.com/

The other way to work around this is to intsall "Process Editor". 解决此问题的另一种方法是安装“流程编辑器”。
Open the "WIT-WorkItem Type" from the server using visual studio. 使用Visual Studio从服务器打开“ WIT-WorkItem类型”。
Select the WorkItem to change from the list of Team Projects and edit the workflow by removing the assignedto=None and changing it to "Required". 从团队项目列表中选择要更改的工作项,然后通过删除assignto = None并将其更改为“ Required”来编辑工作流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM