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
_teamFoundationServer.EnsureAuthenticated();

// 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);
}
else
{
// A workspace was not provided, so return the server item
item = changesetItem.Item.ServerItem;
}

// Do not add duplicate filenames
if (!buildFiles.Contains(item))
{
buildFiles.Add(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

ASP.NET

SharePoint Technologies

Security

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!

25 November 2008

How To: Skip Actions When Queuing a Build

One of the tasks we commonly build into our Team Build scripts is the ability to run FitNesse tests along with other tests (such as unit tests).  If any of the tests fail, we do not deploy the product for user acceptance testing.

The advantage to this approach is that we find out relatively quickly if we have "broke" the build if we have failing tests.  The down side to this is two-fold: 1) the build takes longer to run (not that big of an issue in our case) and 2) Sometimes we refactor code that should break the FitNesse tests.

In the latter case, it may take somebody several hours (or even sometimes, days) to review the failing tests and get them corrected.  In the meantime, none of our updates get deployed for further testing.

Properties to the Rescue

Some time ago, I wrote a short post explaining how to access the various properties, items, and meta data that you can define and/or make use of in your Team Build scripts.  By making use of a simple property declared within the build script we can allow the developers to queue a new build and override the execution of the FitNesse tests so the build can proceed.  Configuring the build script to achieve this requires three steps:

1. Create a custom property that will be used as a flag to determine whether the desired functionality should be executed or overridden (i.e. skipped).  In my example below, I named the property SkipFitNesse.

<PropertyGroup> 
  <SkipFitNesse>false</SkipFitNesse>
</PropertyGroup>

2. Place the task(s) to be executed into a custom target specifying a condition.  For example:

<Target Name="RunFitNesseTests" Condition="'$(SkipFitNesse)' == 'false'">
  < tasks go here... />
</Target>

Notice that the property name, SkipFitNesse, is used in the condition.  As long as it remains set to its default value (in this case, false) the target will execute.

3.  Call the target at the desired point from within the build script.  In the example below, I am calling the target to run the FitNesse tests in the <AfterCompile> target.

<Target Name="AfterCompile" Condition="'$(IsDesktopBuild)'!='true'"> 
   <!-- Run FitNesse tests for Risk Rating -->
  <CallTarget Targets="RunFitNesseTests"/>
</Target>

Now that the build script is setup, you can manually override the execution of the FitNesse tests when you queue a new build by entering the following text into the command-line arguments field:

    /p:SkipFitNesse=true

For example:

queue

With this approach, the developers on our team now have a quick and simple method for skipping the execution of FitNesse tests if they are known to be in a "non-passing" condition and we want the build to continue.  This is only one example of how you might override the value of a property on the queue build dialog.  There are undoubtedly countless uses for this technique.

Also, if you're interested in seeing how we execute FitNesse tests as part of our builds, check out this post.

Omaha Team System User Group

After having to postpone the session from September due to scheduling conflicts we had a great turnout for the Omaha Team System User Group meeting last week.  The speaker for our November meeting was Russ Wagner, an Enterprise Applications Architect at Farm Credit Services of America.

After having some tasty pizza and enjoying a little socializing, Russ presented on the TFS command line utilities and TFS Power Tools related to Team Foundation Server.  The presentation went very well (despite some pre-demonstration glitches) and proved to be very informative.  Although I've had the opportunity to use the majority of the command line tools and TFS Power Tools, it was nice to see them all covered in a single presentation.

Once the presentation was over, we raffled off some books and had some great Q & A with a few of the attendees.  As always, I'm looking forward to our next meeting after the start of the new year.

Click here to download the presentation in PowerPoint 2007 format.

27 October 2008

VSTS 2010 + .NET Framework 4.0 CTP

Microsoft Visual Studio 2010 and .NET Framework 4.0 Community Technology Preview (CTP) has been made available for download (as of 26 Oct 2008).  You can get the latest bits here.

It is about a 7.5 GB download so be prepared for it to take a little while, especially since it was just released.

There is a ton of new functionality in VSTS 2010, far too much to enumerate in this post.  However, you can check this previous post of mine as a starting point for getting more details.

Download VSTS 2010 .NET 4.0 CTP

17 October 2008

VSLive! Las Vegas - Day 3

Well, the "regular" conference sessions are now over.  All that is left is the post-conference session which includes an all-day hands on lab for LINQ.  I will spend part of the day in this session until it's time to head to the airport.

Once again, I spent the last session day in ALM sessions related to Team Foundation Server.

The first session of the day was mine, "Using Team Foundation Build in the "Real" World".  I thought the session went very well (I suppose the feedback will tell the real story :-).  There was great attendance and a lot of great questions being asked.  I really enjoyed presenting at VSLive! and hope to do it again in the future.

The remaining sessions covered implementing cross platform/language builds using TFS, migration vs. integration of TFS, and programming the TFS object model.

Although the sessions were great, I enjoyed talking to the other attendees and speakers the most.  It's always nice to meet other people facing the same issues as you and that have the same interests.  Because of the sessions I attend and the people I talked to, I have a lot of new information, techniques, and practices that I can take back with me and apply to my daily work.

All in all, it's been a great week at VSLive! Las Vegas.  I may have even set some kind of world record while being here - I'm not much of a gambler and, in fact, I may be the first person ever to stay in Las Vegas for five days without gambling a single cent :-)  I did enjoy a lot of other attractions while here in Las Vegas, however.  I attended a show (the Phantom of the Opera), spent time swimming (don't get a chance to do that much at home), walked the "strip" countless times, watched a battle between two pirate ships, and spent an average of $20-$25 on just about every meal I ate :-)  Speaking of food, the lunch meals provided during the conference were second to none.

If you're interested in the slides from my presentation, you can get them here.

TFSInfo Updated for TFS 2008 SP1

The TFSInfo utility has been updated for TFS 2008 Service Pack 1.  This update includes the following changes:

  • UPDATE: TFSInfo will correctly report TFS 2008 SP1 when it is installed.
  • UPDATE: TFSInfo now displays the TFS installation folder.
  • FIX: TFSInfo now finds the TFS installation folder when it has been installed in a non-default location.

TFSInfo_v2.1.0.0

You can see from the screen shot which information is displayed.  In case you can't see the image, the following information is displayed by TFSInfo:

  • AT Server Name
  • AT Version
  • AT Edition (e.g. Standard, Workgroup, or Trial)
  • TFS Installation Folder
  • DT Server Name
  • DT Server Version (not available for TFS 2008)
  • SQL Server Version
  • Reporting Server URL
  • TFS Installation Date
  • TFS Product ID

You'll notice in the list above that the Data Tier schema version is not available for TFS 2008.  This is because the column that's used to determine the schema version in TFS 2005 does not exist in TFS 2008.  I haven't had any luck locating the schema version in any other table in the set of TFS 2008 databases.  If I am able to determine how that information is stored (assuming it is) I will release an update.  Another update will be released shortly following the next Visual Studio 2010 CTP (due out in the next couple of weeks during the PDC).

The new version can be downloaded here.

NOTE: The Team Explorer Client 2005 or 2008 needs to be installed for TFSInfo to work.

Click here to view the original post.

16 October 2008

VSLive! Las Vegas - Day 2

Day 2 is now a wrap and the conference continues to go strong.  As you may have suspected, I spent my time in the ALM sessions around the subjects of TFS Work Item Tracking, Team System Add-Ons, and Branching Strategies.  All the sessions I attended were very good although I didn't attend every session because I spent a little time polishing up my slides and demos for my talk on Thursday morning (Using Team Build in the "Real" World).

I would have to say my favorite talk of the day was the one on Branching Strategies by Jeff Levinson.  There was definitely some good information coming out of this presentation that can be applied today on our projects.  I'll be picking Jeff's brain over the next few months attempting to learn everything he knows about branching (if that's possible :-)

15 October 2008

VSLive! Las Vegas - Day 1

The first day of VSLive! Las Vegas is now in the books.  This is my first time attending a VSLive! conference so I wasn't sure what to expect.

The keynote was given by Stephanie Saad, the Group Program Manager for Visual Studio Team Foundation Server.  She discussed the use of Team Foundation Server throughout Microsoft and some of the challenges they ran into while using the product.  The scale at which they make use of Team Foundation Server is somewhat staggering in comparison to the seven developer teams at the company I work for.  Along with one of her co-workers, I don't recall the name (sorry), they also presented some of the new features that will be available in VSTS 2010 - mostly around the tracking and reporting of project-related data in Microsoft Excel.

I spent most of the rest of my time in TFS-related sessions with speakers such as Benjamin Day and Brian Randell.  All in all, it was a great start to the conference.  So far, based on the size of the conference rooms, the number of attendees, and the speakers, I would have to say it's relatively comparable to the Heartland Developers Conference.

Being in Las Vegas for the first time, I decided I had to check out at least one show.  So, I decided to go to the Phantom of the Opera at The Venetian.  I've seen Andrew Lloyd Webber's Phantom of the Opera in Des Moines and Omaha and thought I could use those shows as a basis for comparison.  I must admit, the show at The Venetian pretty much blew the others away!  In all fairness, the show at The Venetian has a dedicated stage and auditorium built solely for the purpose of The Phantom of the Opera.  This allows the effect to be top notch.  Although I'm not sure who was playing the parts of the Phantom, Christine, etc. the singing was phenomenal.  If the other shows in Las Vegas are of this caliber of quality, then there are indeed a lot of great shows in this town :-)

14 October 2008

Visual Studio 2010 Links

There has been a lot of information coming out over the past couple of weeks regarding Visual Studio 2010 so I thought I'd consolidate a list of links that provide some information about what may be included in the next release:

Informational Posts

PodCasts and Videos

BLOGs

There are a lot more blogs related to Team System than these listed below.  However, these are some of the blogs I read more often:

There is no doubt a lot of other information out there but this should help you get started if you're just now starting to take a look at what's coming down the road with Visual Studio 2010.