How to determine if the source code for a TFS project has been changed

I have a Visual Studio C # project in TFS that compiles into a DLL. I need to know if any of the files within the project have been modified over a certain period of time. Something like that:

"from date 01/01/2011 to today, check if the project has been modified." 

What is the best approach for this using the TFS API in C #?

My idea is to get all project elements from TFS, as each element checks its history change. Filter the history according to the specified period. If changes occurred during this period, then this file was changed, so the project was changed. Is it correct?

Is it possible to do the same, but not look between the time period, but in a number of sets of changes? For instance:

 "from changeset 1071 to latest, check if the project has been modified." 
+4
source share
3 answers

You can use the QueryHistory method for these types of questions:

 var tfs = new TfsTeamProjectCollection(new Uri(@"http://tfs.example.com:8080")); var vc = tfs.GetService<VersionControlServer>(); // DateTime fro, to; var changesets = from cs in vc.QueryHistory( "$/YourProject", VersionSpec.Latest, 0, /* deletion ID, 0 otherwise */ RecursionType.Full, null, /* user, null for all */ null, /* from changeset, null because these aren't by date */ null, /* to changeset, null because these aren't by date */ Int32.MaxValue, /* get them all */ false, /* just metadata */ false /* just the current stuff */ ) where cs.CreationDate >= fro && cs.CreationDate <= to select cs; 

After you have a list of change sets, you can request them for the files with which they are associated. At the moment, if you really want to eliminate false positives, I would use Roslyn support to read projects and solutions and use this to filter interesting file names.

+2
source

The problem you will have here is that the project may contain files that are not in the same root folder. In large solutions, files that are outside the project directory are widespread.

Another problem that you will encounter is that not all files in the source control in the project directory must be included in the project.

Now, if you don't care about these cases, the easiest way to do this is to use the tf, tf folderdiff command line. You can give it two paths (which can be like on a server), and although the documentation does not indicate it clearly, you can bind a version option to it as follows:

  tf folderdiff $/Path/To/Project;C1071 $/Path/To/Project;T /recursive 

Examples of what you can use for are described here . It includes dates, change set numbers, label names, etc.

If you want to know how to do this, consider viewing the tf.exe utility in Reflector.NET or JustDecompile (or a similar application). They use the same API as you. Or simply invoke the tf folderdiff directly using the Process class.

I have a post explaining a bit more about the tf folderdiff command and how to use it.

The class containing the magic is here:

  internal class FolderDiff : IEnumerable<FolderDiffFolder>, IEnumerable, IDisposable Name: Microsoft.TeamFoundation.VersionControl.Controls.FolderDiff Assembly: Microsoft.TeamFoundation.VersionControl.Controls, Version=11.0.0.0 

It is internal, so you can see how this is done, but there is no easy access to the API to get the same result.

+2
source

I'm not quite sure why @Alex deleted his answer since this is basically a good start.

As he suggested, you can run tf.exe to get the history in a hierarchy of files or entire folders, and you can limit the results between two versions, changeets or dates. Therefore, if your project is β€œnormal” and almost everything is in the same root folder, the simple way is to tf history in the root folder only to get a list of files that have been changed. You will have to analyze the output to determine which files are affected, but what is a fairly simple task is even easier if all you want to know is β€œhas anything changed?”.

As @jessehouwig says, there may be files that you want to view from other places, and files in the project folder that you don't want to view. In this case, you can write a batch file or application that calls tf.exe several times to collect information in a more specific way.

0
source

All Articles