In a previous post - Getting started with Lab Management (Part 4), we saw how to deploy a simple application to a Lab Environment. In this post, I will describe how to add more realistic steps which may be required to deploy your application.

For testing a multi-tier ASP.NET MVC web application, I have created a Lab Environment with 2 machines. One of the machines is the Web Server and the second one is the Database Server.

The Application has a Web Application Project which needs to be deployed on the Web Server and a Database Project which needs to be deployed on the Database server.I will use Web Deployment Tool (MS Deploy) to deploy the Web application to the Web server. I will use VSDBCMD tool to deploy my database to the Database server. You need to install the Web Deployment Tool on the Web Server & VSDBCMD on the Database server.

In the Deploy section of the Lab Workflow Parameters, we can run scripts on each machine in the Lab Environment. Note that we can run multiple scripts on the same machine. In the screenshot below, you can see that I have two scripts running on my Web machine and one script running on my Database machine. Each of these scripts is a bat file which performs multiple setup actions.


In the Deploy section of the Lab Workflow Parameters, I am using the following in-built macros.

$(BuildLocation) –> Name of the folder in which the build output is copied.

$(InternalComputerName_Web) where Web is the name of my VM – This macro returns the hostname of the Web VM.

Web Deployment tool takes a web package as its input. To generate this package, pass the following arguments to MS Build. /p:DeployOnBuild=true as shown in the picture below.


When the Database project is compiled, we get a set of files which can be used as input to the VSDBCMD utility.

We run the VSDBCMD utility on the Database server to create the tables and pre-populate them with initial data.

The setup script (.bat file) that I run on the Web Server is as below.

REM Usage: Build Location, DB Server Name, .NET version

REM Add a handler for ASP.NET MVC

%WINDIR%\System32\inetsrv\appcmd set config /section:handlers /+[name='MVC',path='*',verb='*',modules='IsapiModule',scriptProcessor='%WINDIR%\Microsoft.NET\Framework\%3\aspnet_isapi.dll',resourceType='Unspecified',requireAccess='None']

REM Deploy the Web Application using Web Deployment Tool

cmd /c %1\_PublishedWebsites\TailSpin.Web_Package\TailSpin.Web.Deploy.cmd /Y %2

REM Restart IIS


NOTE: You should add more error handling in this script. I have kept it simple to improve readability.

The setup script (.bat file) that I run on the DB server is as below.

REM Usage: Domain name, Web Server name, Build Location

REM Copy required files to a local folder

REM xcopy %3\TailSpin* c:\tailspin /cherky

REM Create the database and tables using VSDBCMD

"%PROGRAMFILES%\Microsoft Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd" /a:Deploy /dd+ /dsp:sql /model:TailSpin.schema.dbschema /manifest:Tailspin.Schema.deploymanifest

REM Run a script to update settings and pre-populate some data.

REM Web Server name is being passed below to provision it to access the database.

"%PROGRAMFILES%\microsoft sql server\100\tools\binn\sqlcmd.exe" -S .\sqlexpress -v DOMAIN_NAME=%1 -v MACHINE_NAME=%2 -i "%3\Scripts\SetupBE.sql"

With the scripts as described above and the Lab Deployment workflow, I am able to automatically deploy my multi-tier application to the lab environment.