Click here to Skip to main content
15,885,278 members
Articles / DevOps / TFS
Tip/Trick

Executable Utility to get file list changed in a particular changeset

Rate me:
Please Sign up or sign in to vote.
1.14/5 (4 votes)
4 Sep 2018CPOL1 min read 6.3K   3
c#, TFS, Get ChangeSet Files , Executable Utility

Introduction

The Executable gets the files from the TFS and gives the list in the console or in a text file

Background

Microsoft TFS application and any sidekick utilities didnt have the feature of copy pasting or exporting the list of files in a particular changeset. Though there are tfpt command line tools, this doesnt give the list as a dump.

Using the code

We need to have a simple poco class with a reference to the Nuget package

Microsoft.TeamFoundationServer.Client 15.112.1

Microsoft.TeamFoundationServer.ExtendedClient 15.112.1

 I have used Visual Studio 2015

C++
using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TFSGetChangeset
{
    class Program
    {  
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("Please enter arguments.");
               
            }
             
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://tfspathtotheCollection"));
            string path = args[0];
            new System.Net.NetworkCredential(args[1], args[2]);
            tpc.EnsureAuthenticated();
            VersionControlServer vcs = tpc.GetService<VersionControlServer>();
            List<string> files = new List<string>();
            int cid = vcs.GetLatestChangesetId();
            
            var history = vcs.QueryHistory(path, RecursionType.Full, 10);
            Console.WriteLine("********************************************");

            Changeset changeset = vcs.GetChangeset(Convert.ToInt32(args[3]));

            if (changeset.Changes != null)
            {
                foreach (var changedItem in changeset.Changes)
                {
                    string item = changedItem.Item.ServerItem;
                    if (!files.Contains(item))
                    {
                        files.Add(item);
                        Console.WriteLine(item);
                    }
                }
            }
            Console.WriteLine("********************************************");
            Console.ReadLine();
          
              
        }
      

    }
}

 Usage:

tfspathtotheCollection in the code needs to be replaced accordingly

Compile the Project and execute the same as below in the application path from the command line

say: C:\applicationpath:

TFSGetChangeset.exe "$tfspath/branchname" "domain\\user" "password" changesetid >> Outputflle.txt

 

The file Outputflle.txt will have the list of files changes in the changeset.

Points of Interest

Yes, it served my need and got to explore a new library

History

This can be further enhanced as per future requirements, one is to have it implemented for multiple changesets and dump it to text file.

 

The Code has been compiled based on few microsoft code references from web and compiled in to a Utility as per my requirement. Hope it serves others purpose too.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Godrej Infotech
India India
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
Generaltf.exe does that already... Pin
Vijay Gill6-Sep-18 2:04
professionalVijay Gill6-Sep-18 2:04 
GeneralRe: tf.exe does that already... Pin
Hyland Computer Systems6-Sep-18 9:01
Hyland Computer Systems6-Sep-18 9:01 
I think the point of the article is to demonstrate the ability to; say perhaps, save the results to a dB or file: automatically.

Theoretically, this could be set up as a batch script to activate using MSBuild; in which case, it could come in handy.

Thanks author, for sharing.
"Try?! Try, Not! Do... or DO NOT!!" - Master Yoda
"Learn=>Know... Know=>Learn... " - Robert Hyland

GeneralRe: tf.exe does that already... Pin
sumangala k9-Sep-18 23:06
sumangala k9-Sep-18 23:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.