How to list files of a team project using tfs api?

后端 未结 2 1202
执念已碎
执念已碎 2021-01-02 06:19

I am wondering if there is a way for me to list all \'files\' containted in a tfs team project. What I am aiming to do is search for files of a particular name that dont hav

相关标签:
2条回答
  • 2021-01-02 06:44

    This is not a different answer, but simply an upgrade of Vengafoo's code. The TeamFoundationServer class is obsolete in 2011 (not sure when this happened, I just know it is obsolete as of now). Vengafoo's code is from 2009, so that makes sense. Use the TfsTeamProjectCollection class with the TfsTeamProjectCollectionFactory factory class instead.

    Here is the upgrade, just one line of change:

    //TeamFoundationServer server = new TeamFoundationServer("server");
    TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsServerURI:8080/tfs/"));
    
    VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
    
    ItemSet items = version.GetItems(@"$\ProjectName", RecursionType.Full);
    //ItemSet items = version.GetItems(@"$\ProjectName\FileName.cs", RecursionType.Full);
    
    foreach (Item item in items.Items)
    {
        System.Console.WriteLine(item.ServerItem);
    } 
    
    0 讨论(0)
  • 2021-01-02 06:55

    Here is how I've figured out how to list all the files of a TFS Project:

    Add Microsoft.TeamFoundation.Client and Microsoft.TeamFoundation.VersionControl.Client as a reference to your project.

    Add a using for Microsoft.TeamFoundation.Client and Microsoft.TeamFoundation.VersionControl.Client

    TeamFoundationServer server = new TeamFoundationServer("server");
    VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
    
    ItemSet items = version.GetItems(@"$\ProjectName", RecursionType.Full);
    ItemSet items = version.GetItems(@"$\ProjectName\FileName.cs", RecursionType.Full);
    
    foreach (Item item in items.Items)
    {
        System.Console.WriteLine(item.ServerItem);
    }
    

    The second GetItems will restrict the items found to those of a specific filename. I just have this sample outputting the server path for all of the files found.

    0 讨论(0)
提交回复
热议问题