30 December 2008

Get Files Associated with a Build

One of the greatest features of Team Foundation Server is it's extensibility via the TFS Object Model.  A short while back I received a question asking how to retrieve a list of all files included in all the changesets associated with a build.  The intent (of the person asking the question) was to deploy only those files that had been modified in one of the changesets.

The following code example is what I came up with.  I can't say it's the only way, or even the most efficient way, to achieve the desired result, but it's at least one way :-)  I've also posted this example on TFSExamples.com, here.

/// <summary>
/// Gets a list of files included in all changesets associated with the specified build URI.
/// </summary>
/// <param name="tfServerName">The name of the Team Foundation Server server.</param>
/// <param name="buildUri">The URI of the build to retrieve items for.</param>
/// <param name="workspaceName">The name of the workspace that's used to map server items
/// to local items (e.g. to a file on the client machine).</param>
/// <param name="workspaceOwner">The workspace owner.</param>
/// <returns>A list of files included in all changesets associated with the specified
/// build URI.</returns>
/// <remarks>You can specifiy an empty/null <paramref name="workspaceName"/> and/or
/// <paramref name="workspaceOwner"/> if you want a list of server items returned.</remarks>
private List<string> GetFilesAssociatedWithBuild(string tfServerName, Uri buildUri, string workspaceName, string workspaceOwner)
var buildFiles = new List<string>();
Workspace workspace = null;

// Obtain cached instance of TeamFoundationServer (if a match is found). If the current credentials are not
// valid, then a connection dialog will be displayed when EnsureAuthenticated is called below
var tfServer = TeamFoundationServerFactory.GetServer(tfServerName, new UICredentialsProvider());

// Ensure the current user can authenticate with TFS

// Get a reference to the build service
var buildServer = (IBuildServer)tfServer.GetService(typeof(IBuildServer));

// Get a reference to the version control service
var versionControl = (VersionControlServer)tfServer.GetService(typeof(VersionControlServer));

// Get the workspace used to map server items to local items
if (!string.IsNullOrEmpty(workspaceName) && !string.IsNullOrEmpty(workspaceOwner))
workspace = versionControl.GetWorkspace(workspaceName, workspaceOwner);

// Get the build specified by the selected build URI
var build = buildServer.GetBuild(buildUri);
if (build != null)
// Get a list of all changesets associated with the selected build
var changesets = InformationNodeConverters.GetAssociatedChangesets(build);
if (changesets != null)
// Iterate through all changesets associated with the selected build
foreach (var changesetSummary in changesets)
// Get the changeset for the specified ID
var changeset = versionControl.GetChangeset(changesetSummary.ChangesetId);

if (changeset.Changes != null)
// Add each file associated with the current changeset
foreach (var changesetItem in changeset.Changes)
if (workspace != null)
// Since a workspace is available, map the server item to a local item
item = workspace.GetLocalItemForServerItem(changesetItem.Item.ServerItem);
// A workspace was not provided, so return the server item
item = changesetItem.Item.ServerItem;

// Do not add duplicate filenames
if (!buildFiles.Contains(item))
return buildFiles;

04 December 2008

Microsoft Learning & Hands-On Labs

If you've never checked out the Microsoft Learning site I would recommend giving it a look.  This site provides a great deal of training-related information for various Microsoft products.  You can easily find training for a variety of products based on the learning resource types, technologies, or subjects.

You can also search for a specific exam and get detailed information on what materials are available for use in preparing for the exam.  It will also give you other useful information such as what certifications does the exam apply to.

Another cool feature of the site are the Learning Plans.  There are several pre-defined learning plans that allow you to easily add a group of learning resources to your "My Learning" page.  For example, you can select the Learning Plan for MCPD Certification as a Web Developer and get a list of steps that you can follow to achieve the MCPD Certification as a Web Developer.

The best part of this site is that a lot of the content is offered for free (who can resist free on-line training? :-).  As of this post, here is a list of the developer-related e-learning modules available for free (or you can view all current free items on-line by clicking here):

Distributed Applications

Windows and Smart Client

.NET 3.0


SharePoint Technologies


Microsoft BizTalk

Microsoft SQL Server

Hands-On Labs

There are also several hands-on labs available for free.  Here is a short list of a few of them - I have no doubt there are others available as well:

Happy learning!