none
TFS是否支持自动添加bug?有相关的API吗? RRS feed

  • 问题

  • 想写个工具,自动在TFS中添加、修改bug,请问有相关的API吗?有示例代码就更好了,想用C#写。别的语言的示例代码也行,非常感谢!
    2012年6月11日 9:13

答案

  • Hi,

    你可以使用以下代码来创建一个简单的Bug:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    using Microsoft.TeamFoundation.Client;
    using System.Net;
    namespace Model.workitem_tracking
    {
        public static class CreateWorkItem
        {
            public static void CreateWorkItems()
            {
                NetworkCredential cre = new NetworkCredential("username", "password", "domain");
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://TFSServerName:8080/tfs/CollectionName"), cre);
                
                WorkItemStore wis = tfs.GetService<WorkItemStore>();
                var type = wis.Projects["SourceControl"].WorkItemTypes["Bug"];
                var wi = type.NewWorkItem();
                wi.Title = "WorkItemTFSAPI";
                RegisteredLinkTypeCollection linkTypes = wis.RegisteredLinkTypes;
                RegisteredLinkType testresult = linkTypes["Test Result"];
                ExternalLink el3 = new ExternalLink(testresult, "D:\\unittest.trx");
                wi.Links.Add(el3);
                wi.Save();
                Console.WriteLine(wi.Title);
                Console.ReadLine();
            }
        }
    }


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us

    2012年6月12日 9:52
    版主
  • Another option is you could try the power tool of TFS (TFPT) to create work items via commands in your code:

    tfpt workitem /new type /fields:[field1=value1[;field2=value2;...]|@filename]

    For example:

    Creating a new Bug work item with a title of 'New' and assigned to Jason
    tfpt workitem /new project1\Bug /fields:"Title=New;Assigned To=Jason"


    Lingling Tong - Expression Blend

    2012年6月14日 4:58

全部回复

  • Hi,

    你可以使用以下代码来创建一个简单的Bug:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    using Microsoft.TeamFoundation.Client;
    using System.Net;
    namespace Model.workitem_tracking
    {
        public static class CreateWorkItem
        {
            public static void CreateWorkItems()
            {
                NetworkCredential cre = new NetworkCredential("username", "password", "domain");
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://TFSServerName:8080/tfs/CollectionName"), cre);
                
                WorkItemStore wis = tfs.GetService<WorkItemStore>();
                var type = wis.Projects["SourceControl"].WorkItemTypes["Bug"];
                var wi = type.NewWorkItem();
                wi.Title = "WorkItemTFSAPI";
                RegisteredLinkTypeCollection linkTypes = wis.RegisteredLinkTypes;
                RegisteredLinkType testresult = linkTypes["Test Result"];
                ExternalLink el3 = new ExternalLink(testresult, "D:\\unittest.trx");
                wi.Links.Add(el3);
                wi.Save();
                Console.WriteLine(wi.Title);
                Console.ReadLine();
            }
        }
    }


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us

    2012年6月12日 9:52
    版主
  • Another option is you could try the power tool of TFS (TFPT) to create work items via commands in your code:

    tfpt workitem /new type /fields:[field1=value1[;field2=value2;...]|@filename]

    For example:

    Creating a new Bug work item with a title of 'New' and assigned to Jason
    tfpt workitem /new project1\Bug /fields:"Title=New;Assigned To=Jason"


    Lingling Tong - Expression Blend

    2012年6月14日 4:58
  • How to use it in linux env? Any solution? Thanks.
    2013年1月25日 9:52
  • I tried your solution with my parameters as follows, but it failed with "Unknown field: Title" .

    tfpt.exe workitem /new "Cloud"\Bug /collection:http://tfs:8080/tfs/tpcollection /fields:"Title=tfpttest;Assigned To=sam"

    Anything wrong?

    2013年2月4日 7:41