创建TFS项目

时间:2015-10-15 20:43:30

标签: c# tfs automation

我正在尝试自动创建和管理TFS项目。我有以下代码来创建TFS项目:

try
{
    Uri collectionUri = new Uri("http://TFSServer:8080");
    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);

    WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
    Project teamProject = workItemStore.Projects["ProjectName"];
    WorkItemType workItemType = teamProject.WorkItemTypes["ProjectNameTask"];

    WorkItem userStory = new WorkItem(workItemType)
    {
        Title = "Recently ordered menu 2",
        Description = "As a return customer, I want to see items that I've recently ordered",
        State = "Proposed"

    };

    var invalidFields = userStory.Validate();

    userStory.Save();
}
catch (Exception exception)
{
    Console.WriteLine("Exception occurred: " + exception.ToString());
    throw;
}

调用userStory.Validate()返回invalidFields中的一个带有详细信息的项目:

Name: Issue Type
ReferenceName: IssueType

但是,WorkItem没有IssueType类型的元素。因此,以下代码给出了编译错误:

WorkItem userStory = new WorkItem(workItemType)
{
    Title = "Recently ordered menu 2",
    Description = "As a return customer, I want to see items that I've recently ordered",
    State = "Active",
    IssueType = "Some Issue"

};

错误说&#34;无法解析符号&#39; IssueType&#39;&#34;。这可能是因为我无法访问特定TeamProject的正确dll。我认为解决以下两个想法之一可能会有所帮助:

如何为特定的TeamProject的WorkItem获取正确的dll?

是否可以向对象类型添加字段?我尝试通过扩展WorkItem来创建一个新类,但它是命名空间Microsoft.TeamFoundation.WorkItemTracking.Client中的一个密封类。

想知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

工作项可以包含远远超出WorkItem类型中表达的任意字段。在Fields属性中查找您所追踪的字段。

例如,userStory.Fields["IssueType"].Value = "Value"