Fetching file history from TFS : the code way
These days I’m writing a tool for Visual Studio that integrates with Team Foundation Server. This post is about how to retrieve/fetch history of a file from source control server using TFS-SDK. Following function takes server name and file path as input and returns an enumerator holding Changeset objects.
public static IEnumerable FetchHistory(string serverName, string filePath)
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(serverName);
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
ExtendedItem[] itemArray1 = vcs.GetExtendedItems(filePath, DeletedState.NonDeleted, ItemType.Any);if ((itemArray1 == null) || (itemArray1.Length == 0))
throw new Exception(“There are no items.”);ExtendedItem item1 = itemArray1[0];
IEnumerable enumerable1 = vcs.QueryHistory(filePath,
VersionSpec.Latest, item1.DeletionId,
(item1.ItemType == ItemType.Folder) ? RecursionType.Full : RecursionType.None,
“”, new ChangesetVersionSpec(1),
VersionSpec.Latest, 0×7fffffff, true, false);
return enumerable1;
}
To compile this successfully you also need to add references of following two assemblies found at [VS installation directory]\Common7\IDE\PrivateAssemblies\:
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Call to this function should be made as follows:
FetchHistory(“[serverName]”, “$/Project1/Class.cs” );
- Ankit
brij wrote:
nice blog, i used a post…..cheez thanks
Posted on 20-Dec-06 at 7:04 pm | Permalink
TFS – Free Text search in History Objects - Ye Meri Life Hai! wrote:
[…] Once you have completed the Visual Studio Add-in wizard the IDE generates Connect.cs file and dumps some code for basic functionality. The next step is to retrieve history from the TFS for selected file. Refer my previous post, Fetching file history from TFS to find out how to fetch file history objects from Version Control Server. […]
Posted on 29-May-07 at 1:37 pm | Permalink
Tarun Sukhu wrote:
Hi Ankit,
Your project looks interesting. What level of integration have you achieved. I plan to work on a project where we need to pump in different items (source control , bug information , workflow) from an external system into TFS. Any tips would be good.
Posted on 20-Nov-07 at 1:00 pm | Permalink