Sunday, October 17, 2010

Automating Web Application Deployment .NET v4.0 and MS Deploy

You can also see my code project article Automate Publishing a WebSite into IIS using MSDeploy and NAnt Scripts
I was searching a way to automate publishing my website in staging server. In .NET v4.0 it become very easy to deploy my site in IIS v7 to v5 using msdeploy.exe.
In installation of VS2010 also install MS Deploy in your machine in x:\Program Files\IIS\Microsoft Web Deploy folder. And For deploying WebApplication from VS 2010 it give window like this.
clip_image002
It allows you deploy a web application not only in your IIS but also in remote server. This use web deployment tool (Msdeploy.exe) internally.
you will get major features of Web Deployment in VS 2010 here. http://blogs.msdn.com/b/webdevtools/archive/2009/02/04/web-deployment-with-vs-2010-and-iis.aspx
New command is found /target:package with MSBUILD in .NET v4.0 framework. This create an .zip file with all IIS settings, Web Content , SQL Server DB scripts , and other various artifacts like Security Certificates , GAC components, Registry etc.
The command for creating package of web application project WebApp.csproj is . 
C:\..\MSBuild.exe X:\WebApp.csproj /target:Package
It will create .zip file according to configuration.. as configuration is Debug so it create Package folder under debug. but you can specify your build configuration and set the location of package

C:\..\MSBuild.exe X:\WebApp.csproj /t:Package /p:Configuration=Release /p:PackageLocation=x:\WepApp\WebApp.zip


It creates following files  under x:\WebApp after executing this command. you can see there it contains command file, readme text for helping you to run command file and another xml let you to configure your deployment and manifest file.


Untitled


Now lets see what readme.txt contains. it tell you how to run webapp.deploy.cmd and also to customize your IIS parameters you can change webapp.SetParameters.xml file.  this command file actually run msdeploy.exe  with some commands. The options are given in this txt file. so I am not describing  those options here.

Let see the webApp.SetParameters.xml file. It give you options to change  your web Application name in IIS and also allow you to change your database connection string . I have created an web application “WebApp” under “default web site” site. So I can Set “IIS Web Application Name” as “Default Web Site/WebApp”.Untitled

IIS 7  gives you options to import webapp.zip file with Import WebApplication wizard. For automation you can run web.app.deploy.cmd file.

Now lets run the webapp.deploy.cmd file with the command which allows you to deploy your web application .zip file in local or remote machine.

First see the command for deploying webapp.zip in local machine. but for that you have to create web application in IIS given in webapp.SetParameters.xml file. You can also create Web Application in IIS with msdeploy.exe commands.


Now run this command file from command prompt. you can give /T command as instructed in readme file which not deploy but give you simulation of deployment. but for deploying your web application you use /Y command.


C:\..\webapp.deploy.cmd /Y

You can also deploy your web application in remote server. but for that your remote service should be run in your remote server so that it allowed remote connection. msdeploy use remote connection to deploy your web application. you can install your web appliction in buildserver machine with following command as given in readme file.


C:\..\webapp.deploy.cmd /Y /M:192.168.1.12 /U:milton /P:xxx
But for deploying in remote machine you need to have web deployment agent service on in that machine. And for that you need to install web deployment agent service feature of web deployment tool http://www.iis.net/download/webdeploy . After installing you need to run service. You can check your web deployment agent service agent is running in that machine by http://localhost:80/msdeployagentservice.

The main goal of this article to give you way to automate web application deployment in  IIS 5 to IIS 7 using command. You can integrate into NANT or MSBuild scripts to automate build.

No comments:

Post a Comment