I find that a lot of the applications I write use IIS in some way. Silverlight, ASP.NET, WCF Services – these all usually need an IIS web application in order to run. Since I’m a unit testing / test-driven development kind of a guy and a everything-should-be-repeatable kind of a guy and an if-it-doesn’t-run-from-an-automated-build-then-it-isn’t-real kind of a guy, this means that I’m going to need to deploy my application (Silverlight, WCF, ASP.NET, etc) in to IIS and then make sure that the security settings are all wired up properly.
In TFS2008 and TFS2005, I’d do this using the Tigris MSBuild Community Tasks and the AfterCompile target in the Team Build script. I could still do this in TFS2010’s Team Build implementation but TFS2010’s been re-written to use Windows Workflow (see screenshot below) and I wanted to do this without having to “shell out” to MSBuild.
What does this mean? This means that I needed to write a custom Build Workflow Activity and then create a build that would use this new custom activity.
Here’s the structure of the solution.
Benday.TeamBuild2010 contains the code to manipulate IIS. Benday.TeamBuild2010.Activities contains the two Team Build Workflow Activities – IisDeleteWebApplication and IisCreateWebApplication. Benday.TeamBuild2010.UnitTests contains the automated tests for the code. Since the hard part of this project is interacting with IIS, the unit tests mostly focus on the IisUtility class in the Benday.TeamBuild2010 project.
In my actual build script, I dropped in a Sequence in the Compile and Test Sequence. I named it Set Up IIS and this is where I put my calls to my custom activities.
Inside of the Set Up IIS Sequence, I put in calls to IisDeleteWebApplication and IisCreateWebApplication. When I’m setting up an IIS application from inside of an automated build, I always call for a delete in order to make sure that I’m starting from a clean environment. I want to make sure that there aren’t any weird settings hanging around when I create the web application. I want to *know* exactly what I’m putting on IIS from my build in order to ensure that my build is accurate and repeatable.
The screenshot below is the Properties panel for the IisCreateWebApplication activity.
Here are the properties for IisCreateWebApplication:
|ApplicationName||Name of the application.|
|ApplicationPath||Location of the web application files on disk.|
|AppPoolName||Name of the app pool that your application will run under. If this value is blank, the default app pool will be used.|
|AuthenticationAnonymous||Enables/disables anonymous authentication in the app.|
|AuthenticationBasic||Enables/disables basic authentication in the app.|
|AuthentiationWindows||Enables/disables Windows/NTLM authentication in the app.|
|SetAuthenticationSettings||If this value is set to false, then the activity will not make any changes to the security configuration. If true, the activity will update the security settings for the app.|
|SiteName||Name of the website. If this is blank, it will use the first website in the sites collection. This is usually “Default Web Site”.|
The following sites were essential for figuring out how to implement all this:
Editing IIS settings: https://forums.iis.net/p/1171129/1955125.aspx
How to write to the TFS2010 Build Log & Manage Verbosity: http://www.codewrecks.com/blog/index.php/2010/01/18/set-verbosity-of-logging-during-tfs-2010-build/
How to create an use a custom tfs build workflow activity: http://blogs.msdn.com/b/jimlamb/archive/2009/11/18/how-to-create-a-custom-workflow-activity-for-tfs-build-2010.aspx
What assemblies are required to make your builds compile in Visual Studio 2010: http://www.ewaldhofman.nl/post/2010/04/29/Customize-Team-Build-2010-e28093-Part-4-Create-your-own-activity.aspx
The source code:
Click here to download the source code. The zip contains two other zips: Benday.TeamBuild2010.zip and TeamBuildUtilsBuildEditor_SampleBuild.zip. The first file contains all the source code. The second file is a sample build script with all the required assembly references added to the project.
— Want help customizing Team Foundation Server 2010? Have some complex build scenarios that you want to implement? Need training on how to use Team Foundation Server 2010 and Visual Studio 2010 Ultimate? Interested in learning more about how to do Scrum with Team Foundation Server 2010? Drop us a line at email@example.com