Thursday, March 24, 2011

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

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 have fixed paths within TFS caused by branching ($/MyTeamProject/Main/Build/instruction.xml and $/MyTeamProject/Branches/Release_1.0). Once a file would be found I would like to manipulate it.

I guess that we are talking items when it comes to entities containted within a team project and not traditional files and therefore this might be a bit tricky?

I have seen some samples for manipulating a file but all samples so far have fixed paths.

From stackoverflow
  • 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 comments:

Post a Comment