Attention: We are retiring the ASP.NET Community Blogs. Learn more >

[Team System] Team Building Web Application Projects and Deploying

I've been battling with Team Build and Web Application Project (WAP) solutions. I first thought that Web Deployment Project (WDP) was the way to go, but I found out the hard way that WDP + WAP + Team Build isn't best mates.

What I want to do is to build a number of solutions (which includes a bunch of projects) and after the build has completed, xcopy the web applications to a specific place, like under IIS webroot.

There are many, many different solutions to this scenario, but I think it's a very common one. Here's what I'm thinking of doing now. Step by step dummy:

1. I create a TFS project "WebApplication1"

2. I create a solution called "WebApplication1" with 2 projects in it; "WebApplication1" (WAP) and "LibraryX" (Class library), I create some dummy code where a web page calls some code in the class library (mostly for fun).

3. Compile and test.

4. I add the solution to SourceControl.

5. I then create a new Team Build called "WebApp1". 

6. Go to Source Control Explorer and check out the TFSBuild.proj file for edit, then double click it to edit.

7. Page down to the end of the build file and add (before the </Project> tag):

 <ItemGroup>
  <WebFiles Include="$(BinariesRoot)\Release\_PublishedWebsites\**\*.*"></WebFiles>
 </ItemGroup>
 <PropertyGroup>
  <DeployWebDir>c:\websites</DeployWebDir>
 </PropertyGroup>
 <Target Name = "AfterDropBuild" >
  <RemoveDir Directories="$(DeployWebDir)" Condition="Exists('$(DeployWebDir)')" />
  <MakeDir Directories="$(DeployWebDir)" Condition="!Exists('$(DeployWebDir)')" />
  <Copy
            SourceFiles="@(WebFiles)"
            DestinationFiles="@(WebFiles->'$(DeployWebDir)\%(RecursiveDir)%(Filename)%(Extension)')"
        />
 </Target>

What the stuff above does is that it declares what files to copy (WebFiles) and where these files should go (DeployDir). Then there's a Target section which is called by Team Build after the drop has been made (AfterDropBuild) that removes the old files and copies the files from WebFiles to DeployDir. The $(BinariesRoot) property points to where the files have been built. WAP files are always built to the _PublishedWebsites\<project> directory.

My web application is now deployed to c:\websites\WebApplication1\ and I'm manually creating an IIS virtual directory which will always be pointing at this directory.

There are a number of additional things you might want to do as well, but I just wanted to show you a very simple way of always copying WAP files to the same place after a build.

If you don't want to use the Tean Build drop directory at all, you should be able to skip that step by setting the SkipDropBuild property to true in the TFSBuild.proj file.

MSBuild / Team Build Resources:

List of targets that can be customized in Team Build (like AfterDropBuild in my sample):

http://msdn.microsoft.com/en-us/library/aa337604(VS.80).aspx

MSBuild Task reference:

http://msdn.microsoft.com/en-us/library/7z253716.aspx 

Brennan's blog with a 7 step tutorial on MSBuild:

http://brennan.offwhite.net/blog/2006/11/29/msbuild-basics-1of7/

How to create your own MSBuild task:

http://msdn.microsoft.com/en-us/library/ms400767(VS.80).aspx

 

No Comments