Saturday, December 20, 2008

Doing builds and running unit tests after every check-in has become a standard practice in Agile and non-Agile development teams.  Continuous Integration is the term that describes this process and helps ensure that that nothing has been broken since the last check-in.    One area that is sometimes overlooked is the code generation.    Continuous Generation, the re-generating of code / stored procedures for every check-in and build, should be considered for your TFS builds.  I believe there is a lot of benefit to generating the code with every build.  There are several benefits:

  • Table schema and stored procedure parameters can change.  How do you know that your generated objects are up to date and match the database?
  • It keeps everyone honest so they don’t break the golden rule of never editing generated code.  If the build is going to re-generate the code there’s no way to sneak the semicolon or curly bracket that you manually fix each time after generation.
  • Sometimes we generate just the class we are working on and keep the rest checked in so it doesn’t overwrite the current object.  If any changes are made to the template only this new class will have them.  The other classes will be based on the older version.
  • It gives more credibility to the generation process.  There is sometimes a feeling of nervousness when generating all of the objects.  Since generated code is never edited, you can generate the code as often as you wish.

CodeSmith Tools is the code generation tool that we use.  It offers an easy way to accomplish this from your Team Foundation Builds.   With version 3.2 and newer there is a custom build task included with the Professional edition.  Here is the online help with some information about it.

There are a couple things to consider.  The generated classes will be checked-in to source control.  You will need to check them out before you call the task and then check them back in afterwards. Also, the user guide instructions do not work quite right in the link above.  The guide explains how to use it within your visual studio project.  However, the task needs to be called from Team Build.  Here’s the basic steps and changes for your CI tfsbuild.proj file.

Step 1: Install CodeSmith Professional on your TFS build server.  This will install the MSBuild task and Targets file.   I contacted CodeSmith Tool’s sales department and this does require an additional license for the server.

Step 2: Import the CodeSmith Targets file.  Add the following line just below the import element below the <!-- Do not edit this --> comment.

<Import Project="$(MSBuildExtensionsPath)\CodeSmith\CodeSmith.targets" />

Step 3:  Add TF property in the PropertyGroup element specifying the tf.exe location to be used throughout the process.

<PropertyGroup>
  <
TF>&quot;$(TeamBuildRefPath)\..\tf.exe&quot;</TF>
</
PropertyGroup>

Step 4:  Override the AfterGet target to check out the generated file(s).  This must be called before the CodeSmith task or it will return an access denied error.  This example demonstrates one file but you can use a subfolder or naming prefix for the generated files and recursively check out all of the necessary files.

<Target Name="AfterGet">

    <Exec WorkingDirectory="$(SolutionRoot)\Main\TestCodeSmithMSBuild\"

          Command="$(TF) checkout Measure.cs"  />

Step 5:  Call the CodeSmith task to execute the CodeSmith project(s) in your solution.  This will also be called in the AfterGet target.  Currently the example in the documentation incorrectly shows the CodeSmith task using the ProjectFile attribute.  As the usage description shows, the attribute is actually ProjectFiles. 

<CodeSmith ProjectFiles="$(SolutionRoot)\Main\TestCodeSmithMSBuild\Test.csp"  />

Step 6:  Override the AfterCompile target to check in the updated generated files.  Fortunately TFS will only check in the file if there is a change.  This is good because most of the time re-generating the code should generate the same thing each time.  However, tf.exe returns a code of 1 instead of 0 and results in a partial success of the build.  Use the IgnoreExitCode=”true” to ignore this.  You could additionally update this to create a work item for any other return code.  Here’s a post with a good example of this.

<Target Name="AfterCompile" Condition="'$(IsDesktopBuild)'!='true'">

    <Exec WorkingDirectory="$(SolutionRoot)\Main\TestCodeSmithMSBuild"

          IgnoreExitCode="true"

          Command="$(TF) checkin /comment:&quot;***NO_CI***Auto-Generate&quot; /noprompt /override:&quot;Auto Generate&quot; measure.cs "/>

  </Target>

Step 7:  Undo the check out if the build fails by overriding the BeforeOnBuildBreak.

<Target Name="BeforeOnBuildBreak" Condition="'$(IsDesktopBuild)'!='true'">

    <Exec WorkingDirectory="$(SolutionRoot)\Main\TestCodeSmithMSBuild"

          Command="$(TF) undo /noprompt measure.cs"/>

  </Target>

That is it.  Enjoy!

Mike

Saturday, December 20, 2008 10:49:44 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Sunday, December 07, 2008


A couple weeks ago I started a new and exciting chapter of my career.  After 8 great years at Farm Credit Services of America as a developer and lead developer, I took a new job as a solution consultant with a small, yet proven and experienced consultanting company called Deliveron Consulting Services.   I have no complaints about FCSAmerica and appreciate all of the oportunities that I received while I was there.  It was a great place to work and leaving was one of the hardest decisions I have had to make. I'm going to miss working with all of the great people I have gotten to know.  I felt this was the right opporturnity at the right time for me.  I'm excited to leverage all of my experiences in Team Foundation Server, CSLA.NET, code generation, configuration management, Agile, Biztalk, etc along with the leadership skills in a new environment.  In fact, I have already begun helping one of our clients convert a projects to TFS.  I'm also utilizing Team Deploy to automate their build and deploy process.  I am excited to work with more companies on implementing or improving their implementation of Team Foundation Server.

So this begins a new chapter and I am excited!

Mike

Sunday, December 07, 2008 8:29:11 AM (Central Standard Time, UTC-06:00)  #    Comments [1]  | 
Wednesday, November 12, 2008
Last week I released some minor updates to Team Deploy.  When you use Team Deploy to deploy your MSIs, it will update the build steps and show that it is deploying.  The second feature will now write any non-zero return code to the build log.  Before this, these return codes were being lost.  In the next release of Team Deploy I will build upon this and allow you to pass in an XML file contain return codes.  If they are an error, warning or information.  For errors, I will make it so it will actually fail the build.

Here's the release
http://www.codeplex.com/teamdeploy

Mike

Wednesday, November 12, 2008 10:36:56 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Tuesday, May 27, 2008

Thanks to everyone that attended tonight's Omaha Team System User Group meeting.  I thought it went very well.  It was a good turnout and there were a lot of good questions asked.

Here are the slides from the presentation. 

TFS_Build_Automation.zip (260.07 KB)

Mike

Tuesday, May 27, 2008 9:02:56 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Monday, May 26, 2008

On May 27, 2008 I will be presenting on Build Automation with TFS at the Team System User Group meeting.  This presentation will demonstrate how cool it is to automate the build process and have a little fun along the way by having your automated builds control street lights and lava lamps.  I will cover the creation of automated builds, demonstrate how to create custom build tasks, and go over a Team Deploy custom task project for build automation

This month's meeting will be at:

Farm Credit Services of America
5015 S 118th St
Omaha, NE 68137

Come and check it out!

Please RSVP to Jeff Bramwell if you plan on attending.

I'll post the slides after meeting.

Mike

Monday, May 26, 2008 7:09:47 AM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Saturday, April 05, 2008

The latest version of Team Deploy (0.7.0.2) now contains the Device Controller Task.  This task allows your Team Foundation Server builds to call the x10 Firecracker to control lamps.  http://www.x10.com/automation/firecracker.htm

 See the Team Deploy website on CodePlex for all of the details and files.
http://www.codeplex.com/TeamDeploy

Here's the street light we are using for our builds.

Build Smart Not Hard

Mike

Saturday, April 05, 2008 2:25:32 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Friday, January 18, 2008

Last night I just published my first CodePlex (or any open source project)!  It is called Team Deploy.  This is a collection of custom MSBUILD tasks for deploying applications from Team Foundation Server to a test PCs and servers.  I developed this awhile ago for my work and several of our teams are using these extensively to do daily updates of our internally built applications.   It has been very helpful for us for a number of reasons:

  • Anyone on our team can kick off the Build and Deploy build type in TFS (Not just me doing the builds anymore!)
  • We can use the same MSI to deploy to all are environments.  Great for configuration management.
  • The tasks available allow for killing processes, uninstalling MSIs, stopping/starting windows services, deleting files, and installing MSIs.  See the CodePlex site for more details.

There is not a lot of magic in the background on these, the real magic is actually done with PSTools.  PSTools is a collection of some really handy free utilities by sysinternals (that was bought by Microsoft).  Even if you don't download and try Team Deploy, you should try out PSTools.  Eventually it would be nice to replace the PSTools functionality and bake it into the tasks, but for now, it works fine.

Try it out and let me know if you have any suggestions.
http://www.codeplex.com/teamdeploy

Deploy Smart Not Hard!

Mike

 

Friday, January 18, 2008 1:01:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: