Update : February 27, 2008
Mentioned the location where the MSI File gets created in case of Websetup Deployment owing to a lot of queries on the same in the comments.
Update: February 21, 2008
Posted a Video version of this article
http://geekswithblogs.net/ranganh/archive/2008/02/21/aspnet-2.0-msi-deployment-video.aspx
http://geekswithblogs.net/ranganh/archive/2008/02/21/asp.net-2.0-publish-website-deployment.aspx
http://geekswithblogs.net/ranganh/archive/2008/02/21/asp.net-2.0-precompilation-utility-for-deployment.aspx
Well, you developed a web application. You need to deploy it. With ASP.NET (1.x versions), Visual Studio .NET provided simple way to create setup files for your web applications to make it install as if it were a stand alone application. The whole process was simplified when using Visual Studio .NET 2003's Setup and Deployment Wizard. So with ASP.NET 2.0 and Visual Studio 2005, what is new and what are the different Deployment Models available? Let us explore them one by one.
Web Setup Deployment - Creating an installer file
This option hasnt changed a lot when compared with Visual Studio .NET. Let us explore the steps.
1. Open your website in Visual Studio 2005
2. Right Click on the Solution Name (Solution 'Your solution') and select "Add - New Project". The "Add New Project" dialog appears. Select "Other Project Types" and expand the same. Select "Setup and Deployment" and in the available Templates select "Web Setup Project" and provide a name ex. "WebSetup1" to create the project in the location of your choice
3. Right Click on the "WebSetup1" created above and choose "Add - Project Output" You would be able to see it lists out the available project in the "Project" dropdown. The only option you would find here is "Content Files". Here is where you find the difference. In Visual Studio .NET and ASP.NET 1.x verions you would need to add "Primary Output" option which is the assembly created for your Website. Here in ASP.NET 2.0 there is no default Website Assembly (in other words DLL File and BIN Folder) unless you explicitly create a BIN folder. Hence you just need to select "Content Files" which will bundle up ASPX, Codebehind, Resource Files, Images, Folders etc., Thereafter you can choose to add a "ReadMe.txt" or something that you require by again choosing "Add" but I leave it you as it is completely optional.
Once you are done with adding the required Project Output, Right Click on the "WebSetup1" project and "Build" it. It would create the installer file (MSI File) that can be used for installing your application on different machines.
Make sure you select "Release" Mode in Visual Studio 2005 before creating the Web Setup since that would optimize the binaries for performance.
A lot of people get back to me saying that they couldnt find the MSI File Created. There are two reasons why your MSI file creation was unsuccessful.
1. You chose File - New Project - Setup and Deployment instead of File - Add New - Project - Setup and Deployment. The former one creates a new project with just a websetup. The latter creates the web setup project under the same solution and allows you to add the website output to the web setup
2. The MSI File typically C:\Documents and Settings\<username>My Documents\Visual Studio 2005\Projects\<your Web Project folder> This is even if you had created the website in c:\inetpub\wwwroot because the Solution File typically gets created in the C:\Documents and Settings\<username>My Documents\Visual Studio 2005\Projects\ path unless you modify it. A lot of us could just over see it when creating the project/solution and generally we dont need the solution file so dont bother to look for it. In the case of deployment the MSI File also sits in the same location where the solution file is created and hence this step would help you identify the same.
Website Publish Wizard Deployment
Visual Studio 2005 also provides you with a new "Web Publish Wizard" option where you can publish your websites files to a different machine / directory to a HTTP / FTP or a file share of your choice. Exploring the steps
1. Right Click on your Web Project and select "Publish Web Site". It will prompt you with a "Publish Web Site" dialog where you can specify the path to be published. You can do a variety of options like "Allow this precompiled site to be updatable". What it means is that, the website is precompiled and the codebehind source get into a BIN directory that is created.
2. The ASPX pages, Images etc., and other markup files are copied to the location specified AS IS.
3. You would also find a PreCompiledApp.Config file.
This option is pretty handy if you keep updating the site to a Staging Server on a regular basis since it wouldnt be feasible to create an MSI installer everyday / everytime you want to deploy your files.
Copy Website Deployment
The Copy Website provides you an option to simply copy the source files to a destination folder which can either be on your local machine or an FTP / HTTP Location. The difference in this case is that, the Website is not precompiled. Your Website is copied AS IS and all the files include the code behind files are copied to the destination. However, the Copy Website Deployment does more than merely copying them. When you use Copy Website option it shows the status of the files in the Source and Destination location and you can synchronize them using the "Synchronize" option that would help you maintain similar versions in different locations. Steps herebelow
1. Select your Website Project, Right Click and select "Copy Website"
2. It provides with you an interface listing the "Source" in the left and provides you the option to "Connect" using the "Connect" option to specify the destination. However, it can also be vice versa since you can select "Source" to be your destination location and do a copy back to your local folder as well.
3. The "Synchronize" button helps you to keep the files synchronized. There is also a Log that is created which can be viewed from this interface. In simple terms Copy Website Deployment is deploying the files as is with source/destination file synchronization.
PreCompiled Web Deployment
With all of these options above, you also can manually precompile the whole application using the PreCompilation tool installed with ASP.NET 2.0. Steps herebelow:-
1. Type "cmd" from Run command to open the Command Prompt
2. Navigate (Change Directory - cd) to %windir%\Microsoft.NET\Framework\v2.0.50727
3. Type aspnet_compiler -v /"Your Website Name" -p "Physical Path to your site" "Physical Path to Deployment Location"
4. An ideal example of above would be aspnet_compiler -v /Website1 -p "D:\Projects\Website1" "D:\PreComiled Website1"
5. There are multiple switches which you can try in the above command. You can verify all the options by typing aspnet_compiler -? from %windir%\Microsoft.NET\Framework\v2.0.50727\
Once you run the above command you would notice that in the Deployed location, all the files including ASPX, ASCX are precompiled and dont contain any markup. If you try opening an ASPX Page, you will only find the text "This is a marker file generated by the precompilation tool, and should not be deleted!" and it doesnt contain any HTML markup. This way the site is totally precompiled and can also prevent any one from viewing the source code. You need to specify the "-u" keyword in the above command before the target directory specification, to make this site updatabale.
When to choose what?
Ok, we saw a variety of options on how we can deploy ASP.NET 2.0 applications and a variety always brings in question on when to use what.
While it is absolutely specific to your customer needs or personal preference, an informal thumb rule I would suggest is as follows.
1. Web Setup Installer for major releases which are not frequently updated.
2. Publish Website for day to day update and staging servers where you want source code (code behind / App Code) contents to be concealed by precompiling.
3. Copy Website where you want to do day to day update and synchronization with staging servers where you dont worry about source code being able to be viewed. In other words a simple X Copy with synchronization features.
4. Precompilation using the aspnet_compiler command utility when you want to precompile both the source as well as markup files seeking high performance, security features.
In this article we saw various options for deploying ASP.NET 2.0 Applications. I hope you found it beneficial. If you have queries please post in comments.
The following articles also provide more information on customizing the ASP.NET 2.0 MSI Deployment Model
http://lakshmik.blogspot.com/2006/05/aspnet-20-deployment-installer-for.html
http://lakshmik.blogspot.com/2006/06/aspnet-20-deployment-installer-for.html
http://lakshmik.blogspot.com/2006/09/aspnet-maintaining-versions-in-web.html
Cheers !!!