Tuesday, May 31, 2011

Web Application Automatic Deployment using MsBuild with Microsoft SDC Task Library

Projects commonly have a web application component, be it a front end or in the form of WebServices. This article will demonstrate how the web applications can be automatically deployed and configured under IIS using the Microsoft SDC Task Library extensions for MsBuild.
The SDC Task Library is free and available at http://codeplex.com/sdctasks Over 300 tasks included in this library including tasks for: creating websites, creating application pools, creating ActiveDirectory users, running FxCop, configuring virtual servers, creating zip files, configuring COM+, creating folder shares, installing into the GAC, configuring SQL Server, configuring BizTalk 2004 and BizTalk 2006 etc.

Step 1
Create project xml file and import SDC tasks
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Microsoft.Sdc.Common.tasks"/>

Step 2
Create deployment Work Plan
<Target Name="Deploy_Webapp">
<CallTarget Targets="CopyFolders" />
<CallTarget Targets="SetPermissions" />
<CallTarget Targets="CleanIIS" />
<CallTarget Targets="CreateWebSite" />
Step 3
Implement every Target in Work Plan, let's focus on CreateWebSite. First of all I will create a WebSite and then I will create a VirtualDirectory.
<Target Name="CreateWebSite" DependsOnTargets="CleanIIS">
CreateVirtualDirectory attributes:
  • virtualDirectoryName - name of the virtual driectory to create
  • path - Path to map the virtual directory to.
  • machineName - Machine to add the virtual directory on.
  • appPoolID - Application pool to run the virtual directory under
  • appCreate - Set to "true" to create an application for this virtual directory.
  • webSiteName - Web site to attach the virtual directory onto.
  • authFlags - Authentication flags to apply to the directory.

Step 4
Create batch file to make all this easier to run

IF EXIST %windir%\Microsoft.NET\Framework64\v2.0.50727\ (
%windir%\Microsoft.NET\Framework64\v2.0.50727\msbuild configServer.xml
) ELSE (
%windir%\Microsoft.NET\Framework\v2.0.50727\msbuild configServer.xml
Microsoft SDC Task Library extensions for MsBuild provides us much more options, You can read a manual that comes with it in order to learn more.

Complite Example: here

No comments:

Post a Comment