Skip to main content
Email Password   helpLost your password?

Building and Deploying Web Application in .NET 2.0

"Building your .NET 2.0 web application is easy", you may have heard. Well, it depends on what do you mean by "build" and what do you mean by "easy". At my work place the system admins are spoiled into requiring all deployment be done with .msi files. What they want is click buttons to build the .msi file, run the .msi file on target machine and forget about it. It is developer's job to make sure all the projects are set up properly to accomplish this.

The hard way. To create *.msi file for web applications in Visual Studio .NET 2005, the "recommended" way is:

If you have done this before you will know it is a PITA. Come on, admit it, nobody is going to laugh at you. If you have a lot of web applications, doing the above for all of them is very frustrating and depressing. The part I hate most is customizing GUI in the installer project, in my opinion it is the worst piece of technology from Microsoft.

Now what can we do about it? I worked on this problem intensively for two whole days and came up with a General Installer project that works with every web application I have (cannot guarantee it will work with all of yours though). Here is the idea:

The easy way (for me anyway). To build and deploy a web application, here is all I need to do:

  1. Use "open website" menu to open my web application in Visual Studio.
  2. Use "publish website" menu to create a precompiled website in a selected folder.
  3. Open the General Installer project and the precompiled website in Visual Studio.
  4. Modify Deploy.xml file for my web application.
  5. Add the precompiled website to the installer project as project output. Build.
  6. Run GeneralInstaller.msi on target machine.

The above steps could take a whopping 20 minutes the first time you do it. Note that you don't need to create an installer project for each web application you want to deploy. If you wish, you can make a copy of the General Installer project for each web application and customize it.

Use included batch file. Instead of running GeneralInstaller.msi directly, it is much easier to run the included batch file GeneralInstaller.bat. This file must be placed in the same folder as GeneralInstaller.msi. Using this batch file, you can install the same web application multiple times on the same machine, there is no need to uninstall a previous version.

Deploy to VISTA. If you run either the batch file or the .msi file on a VISTA machine, you will get access denied error. This can be blamed on UAC, of course. What you need is open an Administrator Console (if you don't know how, remember "Google is your friend") and run the batch file from there.

The Details

General Installer. This project is a regular windows setup project generated from Visual Studio 2005. I removed all GUI except the progress bar (you can remove that, too). Then I added two files to this project: DeployHelper.dll and Deploy.xml.

Deploy Helper. This project is a library which contains two classes: ApplicationConfiguration and CustAct. The first class is derived from System.Windows.Forms.Form which handles GUI. The second is derived from System.Configuration.Install.Installer.

The purpose for this library is to relieve the pain of customizing GUI in installer project. It also does a lot of other things which I am not going to describe in this article. Now you have full control of everything. Here is the windows form in this DLL.

GeneralInstaller3.jpg

Target Dir is the physical folder for the current web application.

App Name is the application name in IIS.

Web Site dropdown is used to select one of the available websites on the target machine.

Virtual Dir is the name of the virtual directory in IIS, if you leave this field empty, the web application will be installed on the root of the selected website.

Config File dropdown allows you to pick a file as web.config file for the current web application (it will replace web.config with the file you selected).

Finally, if you want to reset IIS, check the Reset IIS box before clicking the Confirm button.

Deploy.xml. Here is a sample copy of this file. It is used to store default values for the current installation.

<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
    <TargetDir>c:\TestWeb</TargetDir>
    <AppName>TestWeb</AppName> 
    <WebSite>Default Web Site</website> 
    <VirtualDir>TestWeb</VirtualDir>
    <WebConfigReplacement>true</WebConfigReplacement>
    <AppPool>.NET 2.0 Apps</AppPool>
    <DefaultDoc></DefaultDoc>
</Configuration>

Web Application Configuration

If you have only one configuration file (web.config) for all environments, then you need to set the WebConfigReplacement value in Deploy.xml to false.

I assume all configuration settings for a web application are stored in web configuration file. For each different environment, you should have a different web configuration file. These files have to be named like web_test.config, web_prod.config, etc. Otherwise DeployHelper.dll cannot handle it. You can modify DeployHelper.dll to handle configuration settings any way you want.

Note. There are a lot of other options you can set in Deploy.xml file, you need to look in the source code of DeployHelper.dll to find out.

For example, you can specify the name of your preferred application pool in the AppPool element of Deploy.xml. If an application pool with given name is found during deployment, your application will be assigned to this application pool (application pool assignment works only with IIS v6.0+).

Another example is you can specify a default document for your web application in the DefaultDoc element.

Possible Issues

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionI got dizzy Pin
ulai
23:36 19 Oct '08  
GeneralWhy not just copy the files to the production directory? Pin
ToddHileHoffer
3:25 11 Sep '08  
GeneralRe: Why not just copy the files to the production directory? Pin
Xiangyang Liu ???
3:38 11 Sep '08  
GeneralRe: Why not just copy the files to the production directory? Pin
ToddHileHoffer
3:55 11 Sep '08  
JokeRe: Why not just copy the files to the production directory? Pin
Xiangyang Liu ???
6:49 11 Sep '08  
GeneralRe: Why not just copy the files to the production directory? Pin
ToddHileHoffer
7:48 11 Sep '08  
GeneralWeb Deployment Project Pin
rippo
4:45 10 Sep '08  
GeneralRe: Web Deployment Project Pin
Xiangyang Liu ???
5:10 10 Sep '08  
GeneralBrowserDialog violates the COM requirements for an STA thread, it must pump a message loop Pin
Philip Wagenaar
2:50 29 Aug '08  
GeneralRe: BrowserDialog violates the COM requirements for an STA thread, it must pump a message loop Pin
Xiangyang Liu ???
4:44 29 Aug '08  
GeneralRe: BrowserDialog violates the COM requirements for an STA thread, it must pump a message loop Pin
Philip Wagenaar
4:52 29 Aug '08  
GeneralRe: BrowserDialog violates the COM requirements for an STA thread, it must pump a message loop Pin
Xiangyang Liu ???
7:53 29 Aug '08  
GeneralRe: BrowserDialog violates the COM requirements for an STA thread, it must pump a message loop [modified] Pin
Philip Wagenaar
1:36 3 Sep '08  
GeneralRe: BrowserDialog violates the COM requirements for an STA thread, it must pump a message loop Pin
Xiangyang Liu ???
6:02 3 Sep '08  
GeneralDeploy.xml changes ignored Pin
Philip Wagenaar
12:53 27 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Xiangyang Liu ???
14:35 27 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Philip Wagenaar
22:11 28 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Xiangyang Liu ???
7:56 28 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Philip Wagenaar
22:06 28 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Xiangyang Liu ???
2:06 29 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Philip Wagenaar
2:45 29 Aug '08  
GeneralRe: Deploy.xml changes ignored Pin
Xiangyang Liu ???
3:41 29 Aug '08  
RantA MSI for web site projects? Pin
kjmcsd
4:41 26 Aug '08  
GeneralRe: A MSI for web site projects? Pin
Xiangyang Liu ???
5:12 26 Aug '08  
GeneralRe: A MSI for web site projects? (Add connection string to MSI or use Wizard install on first time) Pin
Philip Wagenaar
10:40 26 Aug '08  


Last Updated 9 Sep 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009