Recently I've been dealing a lot with writing application that tie into Team Foundation Server (TFS) so I thought I would share some things about it.
Integrating your .Net applications with TFS is actually extremely easy. Microsoft has provided a nice API for you to use that is "somewhat" documented in the Visual Studio .Net SDK (version 4).
Getting Started Requirements:
- .Net Framework 2.0.
- Team Explorer (You can get it with the TFS Trial download).
- 32-Bit Windows (Unfortunately the DLL's are compiled for x86 only).
Team explorer installed the TFS API's in your ...\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies directory by default.
Since this is just getting started I'm going to keep this demo very basic and just list all of the files that are in TFS's source control service.
First off you'll need to create a new .Net project (Assuming you'll be using VS.Net, I'll be using a C# Console Application).
Next you'll need to add your references (You'll have to browse to these on your hard drive, there in the PrivateAssemblies directory I mentioned above). You'll to add the following assemblies:
- Microsoft.TeamFoundation.Client.dll - This gives us everything we need to connect to TFS.
- Microsoft.TeamFoundation.VersionControl.Client.dll - This gives us access to the source control server in TFS.
Now you'll need to add your using statements:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
Next we need to connect to our TFS server (I'll be doing this in my Main method since I'm using a console application). We can do this by asking the TeamFoundationServerFactory for our server like this:
TeamFoundationServer teamFoundationServer =
TeamFoundationServerFactory.GetServer("MY-TFS-SERVER");
Then we'll need to ask our TFS server for its version control service like so:
VersionControlServer versionControlServer = (VersionControlServer)
teamFoundationServer.GetService(typeof(VersionControlServer));
And now we're set, all we have left to do is ask the version control server for its items using the root path and tell it to use fill recursion and display them:
ItemSet items = versionControlServer.GetItems("$/", RecursionType.Full);
foreach (Item item in items.Items)
Console.WriteLine(item.ServerItem);
It's as simple as that!
Hopefully this will get some of you excited about working with the TFS API. This is just one of the many things I've planned on writing about so stick around!