I will be presenting “Tools for Agile Development: A Developer’s Perspective” at the Charlotte Alt.Net User’s Group May 7th.  Get the details here http://www.charlottealtnet.org/.  Also there will be a second presentation after mine called “PowerShell as a Tools Platform”. 

I better get moving on cleaning up my presentation :)

I have used NAnt and MSBuild for years on many projects and I always thought there has to be a better way to script build processes.  Well I took a look at PowerShell and psake and so far I like it.  psake is a PowerShell script that makes breaking up your build script into target tasks very easy.  These tasks can also have dependencies on other tasks.  This allows you to call into the build script requesting a specific task to be built and have the dependant tasks get executed first.  This concept is not anything new to build frameworks but it is a great starting point to use the goodness of PowerShell in a build environment.

You can get psake from the Google Code repository.  I first tried the download link for v0.21 but I had some problems getting it to run my tasks so I went directly to the source and grabbed the tip version (version r27 at the time) of psake.ps1 and my problems went away. 

You can start off by using the default.ps1 script as a basis for your build process.  For a simple build process that I wanted to have for some of my small projects I wanted to be able to do the following:

  • “Clean”the local directory
  • “Compile” the VS 2008 Solution
  • “Test” the nunit tests
  • “Package” the results into a zip for easy xcopy deployment

Here is what I ended up with as a starting point for my default.ps1.

image

This really doesn't do anything so far except set up some properties for paths and define the target tasks I want to support.  The psake.ps1 script assumes your build script is named default.ps1 unless you pass in another script name as an argument.  Also since the task default is defined in my build script if I don't pass in a target task then the default task is executed which I have set as Test.

Build invoked without any target task:

image

Build invoked with the target task Package specified:

image

So now I have the shell of my build so lets get it to compile my Visual Studio 2008 solution.  All I have to do is add the code to the Compile task to launch VS 2008 passing in some command line options.

image

And here it is in action:

image

Notice I had to pipe the result of the command line call to “out-null”.  If I didn't do this the call to VS 2008 would run in the background and control would be passed back to my PowerShell script immediately.  I want to be sure that my build script would wait for the compile to complete before it would continue on. 

What about if the compile fails?  As it is right now the build script does not detect that the compile completed successfully or not.  VS 2008 (and previous versions of VS) return an exit code that defines if the compile was successful or not.  If the exit code = 0 then you can assume it was successful.  So all we need to do is test the exit code after the call to VS 2008.  PowerShell makes this easy with the $LastExitCode variable.  Throwing an exception in a task is detected by the psake.ps1 script and stops the build for you.

image

I placed a syntax error in a source file and when I call the Test target the Compile target fails and the Test target never executes:

image

Now I want to add in the ability to get the latest code from my source control repository.  Here is were I wanted the ability to support multiple solutions for different source control repositories like Subversion or SourceGear Vault.  But lets get it to work first with Subversion and then later refactor it to support other repositories.  For starters lets simply add the support for getting latest code in the Compile task.

image

As you can see right now this is very procedural and could certainly use some refactoring, but lets get it to work first and then worry about refactoring.  Here it is in action:

image

As I mentioned before I want to be able to support multiple source control solutions.  The idea here is something similar to what CI Factory uses.  In CI Factory you have what is known as a Package.  A Package is nothing more than an implementation of a build script problem for a given product.  For example you might have a source control package that uses Subversion and another source control package that uses SourceGear Vault.  You simply include the package you want for the source control product that you are using.  Psake also allows for you to include external scripts in your build process.  Here is how we would change what we have right now to support multiple source control solutions.

So I created a Packages folder under the current folder that my psake.ps1 script resides. I then created a file called SourceControl.SVN.ps1 in the Packages folder that looked like the following:

image

In the default.ps1 script Compile task I replaced the source control get latest code (told you I was going to refactor it) with a call to the SourceControl.GetLatest function (Line #20).  I also added a call to the psake include function (Line #10) passing in the following “Packages\SourceControl.SVN.ps1”.  Here is what the default.ps1 looks like now:

image

So if I wanted to support SourceGear Vault I would simply create another package file called SourceControl.Vault.ps1 and place the implementation inside the GetLatest function and change the include statement in the default.ps1 script to reference the vault version of source control.  I plan on adding in support for my Unit Tests the same way I did the source control, that way I can easily have support for multiple unit testing frameworks.

Conclusion

As you can see it is pretty easy to use PowerShell to replace your build process.  This post was just a short introduction on how you might get started and end that crazy XML syntax that has been used for so long in build scripting.  I have a lot more to do on this to make it actually usable for some of my small projects but hopefully I can evolve it into something that will be easy to maintain and reliable.  All in all I think PowerShell has some pretty cool ways of scripting some nice build solutions. 

I had a lot of fun presenting at the Lean-Agile Open.  It was a good turnout also.  I think there were at least 15 in my track.  I wanted shout out and thank Guy Beaver from Netobjectives and Ettain group for inviting me to present and making it all happen.  I wish I would of been able to attend Guy's presentation but I was a little bit busy.  Also Steve Collins of Richland County Information Technology gave a powerful presentation on his experiences with Agile.  You could tell he was very passionate about Lean-Agile approaches.

 

If any of you reading this attended my session I welcome feed back both good and bad, just send it along in an email to mlinnen@protosystem.net.  Attached to the end of this post is the slide deck I used in the presentation. 

Here are some links to the tools that I have used and that I spoke about in the presentation:

SourceGear Vault - Source control used by the developers and the build

NUnit - Unit Testing Framework used by the developers for TDD and Unit Tests. Also used in the build.

Test Driven .Net - Visual Studio Add-in used to make doing TDD easier and just launching tests for debug or code coverage purposes.

NCover - Code coverage of unit tests used by the developers and the build.

Rhino Mocks - Mocking our dependencies to make unit testing easier.

CI Factory - This was used to get our build up and running fast.  It includes build script solutions for many different build problems that you might want to solve.  It uses CruiseControl.Net (CCNet) under the hood. 

NAnt - Used to script the build.  If you are using CI Factory or CCNet NAnt is already packaged with these products so there is no need to download it.  The web site is a great resource when it comes time to alter the build.

WatiN - Used for UI Automated testing of web pages.  WatiN was used both by the developers and the build.

Sandcastle - Used by the build to create documentation of our code.

NDepend - Used by the build for static analysis of the code base and dependency graphs.   

IE Developer Tool bar - Internet Explorer add in to analyze web pages. 

Firebug - Firefox addon to analyze web pages.

ScrewTurn Wiki - For documenting release notes and provide a place for customer feedback.

Google Docs - Sprint backlog and burn down charts.

 

As I stated in my session the above tools are what I used and had good success with but my needs may not be the same as your needs so you owe it to your team to evaluate your own tools based on your own needs.

ToolsForAgile.ppt (1.88 mb)