Tom Fischer

  Home  |   Contact  |   Syndication    |   Login
  21 Posts | 0 Stories | 47 Comments | 0 Trackbacks

News

Archives

Post Categories

.NET Framwork

TFS

Tools

Visual Studio

How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008

This question cost my a day of research, so I thought it is only fair to share my results and to have a look up for myself

There are at least four different options:
- going to SQL directly
- Using the tf.exe tool (great for manual lookup)
- Using the TFS Webservices (painful to use)
- Using the Microsoft.TeamFoundation Libraries, which wrapp the the TFS Webservices   (integrated into .NET)

Going to SQL directly:

See Tad Beaty's Blog

Using the tf.exe

The command line tool does an excelent job, but you have to parse it. Which I don't want to do. But it works great

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>tf status /s:<TfsServer>  /recursive /user:* /format:detailed

Get more infos on MSDN:
http://msdn.microsoft.com/en-us/library/cc31bk2e(vs.80).aspx

The TFS Webservices

http://blog.phase2int.com/?p=141  has a list of all Availalbe Webserices exposed by TFS.

What I read is that MS disencourages you to use these directly. MS advises you to use the API (next chapter). But if you need remote access then this is your best shot.

 If you don't need remote access you might want to consider the next option.

The Microsoft.TeamFoundation Libraries

I found multiple names for them: TFS SDK, TFS object access, etc.
But in the end they all refer to the MS dlls, which are used to access the TFS Webservices:
- Microsoft.TeamFoundation.dll
- Microsoft.TeamFoundation.VersionControl.Client

They can be found in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies

Below is the code you can use to pull all the changes now:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

public static void GetPendingChanges(string tfsServer)
{
 //connection to TFS Version Control    
 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("<YOUR tfsServer>");
 VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

 //pulling the pending changes    
 PendingSet[] pending = vcs.GetPendingSets(new string[] { "$/" }, RecursionType.Full);
 
 //start printing them on the screen:    
 foreach (var item in pending)
 {
    Console.WriteLine("\n--------------------------------");
    Console.WriteLine("User: " + item.OwnerName);
    if (item.PendingChanges != null)
    {
        Console.WriteLine("Number of Checked Out Files: " + item.PendingChanges.Length.ToString());
        Console.WriteLine("Files:");
        foreach (var change in item.PendingChanges)
        {

           Console.WriteLine("-File: " + change.ServerItem);
           Console.WriteLine("-- ChangeType: " + change.ChangeTypeName);
           Console.WriteLine("-- Checked Out: " + change.CreationDate.ToString());
           Console.WriteLine("-- Local file" + change.LocalItem);
        }
    }
 }
}

Of course this is not even the tip of the iceberg. There is so much more in the Libraries. I recommend you check out MSDN for the TFS SDK.

There might be more on the blog in the future :-)

Tom

posted on Wednesday, September 17, 2008 10:28 AM

Feedback

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 9/17/2008 2:09 PM rusty
Wow, I thought there was just a webservice (not that I looked!). I have used Team Foundation Sidekicks by Attrice to do the same thing when I managed a team's checkins.

http://www.attrice.info/cm/tfs/

Nice post.

rusty

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 9/18/2008 2:23 PM ET
I was going to say the same look at the TFS Sidekicks from Attrice. Nice of you to document the way to do it in code.

Cheers,

ET

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 9/19/2008 1:16 PM Tom Fischer
Yep, I started with the sidekicks and used reflector to see how they retrieve the data. And as soon as I saw the references one and one came together. I guess as soon as you know what to look for it is straight forward. But to get there took me some time.

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 9/22/2008 10:56 AM Jesse
I've also had a good experience collecting this info directly from the TFSVersionControl SQL database with some SQL queries. From there, I turned it into a simple report in Reporting Services with scheduled delivery to break down users with long outstanding pending changes that were never checked in (i.e. people with stuff checked out for more than 24, 48, and 72 hours).

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 2/3/2009 7:10 PM Thomas W. Brown
Very nice! Here's a Powershell version:

[system.reflection.assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | out-null
[system.reflection.assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client") | out-null

$tfserver = new-object -typename Microsoft.TeamFoundation.Client.TeamFoundationServer -argumentlist "YOUR SERVER HERE"
$vcserver = $tfserver.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])

write-host "NetworkID `tPath"
write-host "--------------`t--------------------------------------------------------"
foreach ($changeset in $vcserver.GetPendingSets("$/", [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full) | sort -property OwnerName)
{
foreach ($pendingchange in $changeset.PendingChanges)
{
$user = $changeset.OwnerName
$item = $pendingchange.ServerItem
write-host "$user, `t$item"
}
}


# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 2/16/2009 11:07 AM Tom
Thanks for the great snippet for the powershell!!!
Tom

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 2/17/2009 11:12 AM Ganesh Murthy
Wow, this is exactly what I was looking for. Thank you very very much

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 2/17/2009 11:25 AM Ganesh Murthy
There was a small error in your C# code. I have corrected it below

public void GetPendingChanges(string tfsServer)
{
//connection to TFS Version Control
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://10.7.13.60:8080");
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

//pulling the pending changes
PendingSet[] pending = vcs.GetPendingSets(new string[] { "$/DMV/ModularClient/" }, RecursionType.Full);

//start printing them on the screen:
foreach (PendingSet item in pending)
{
Console.WriteLine("\n--------------------------------");
Console.WriteLine("User: " + item.OwnerName);
if (item.PendingChanges != null)
{
Console.WriteLine("Number of Checked Out Files: " + item.PendingChanges.Length.ToString());
Console.WriteLine("Files:");
foreach (PendingChange change in item.PendingChanges)
{

Console.WriteLine("-File: " + change.ServerItem);
Console.WriteLine("-- ChangeType: " + change.ChangeTypeName);
Console.WriteLine("-- Checked Out: " + change.CreationDate.ToString());
Console.WriteLine("-- Local file" + change.LocalItem);
}
}
}
}


# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 2/17/2009 9:47 PM ftom
Thanks for the code update!

# re: How to pull all Pending Changes (Checked Out Items) from TFS 2005 or 2008 1/6/2010 1:35 PM Jimmyd
I am using a custom Check-In policy, but need to know if the file being check in has been altered from what exist in TFS. I tried a file compare but it fails when it goes to open the Server's file...
code snipet...
For Each pc As PendingChange In PendingCheckin.PendingChanges.CheckedPendingChanges

If FileCompare(pc.LocalItem, pc.ServerItem) Then
...
Any suggestions?

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: