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