An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Tuesday, July 31, 2007 11:20 PM

Update : February 27, 2006

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, 2006

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.

Cheers !!!


Feedback

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Hi Harish, I followed your instructions "Web Setup Deployment - Creating an installer file" but no .msi file is being created (that I can find). Any ideas what I might be doing wrong? 9/3/2007 1:33 PM | rob

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Thanks Harish - turned out to be that I needed to enter a licence key value for a redistributable library. Thanks for your response. 9/3/2007 6:03 PM | rob

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

i am not finding any .msi file in realese folder..........wnt can i do now? 9/15/2007 12:14 AM | sunil

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

hi harish

i am very thank ful to u .

i follow ur instructions but i dont find any .msi file

whats the problem i cant understand

pls help me
12/19/2007 7:10 PM | SOMASEKHAR

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

hi harish

i am very thank ful to u .

i but i dont find any .msi file

whats the problem i cant understand

pls help me
12/19/2007 7:24 PM | SOMASEKHAR

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

I want the steps for creating setup and deplyment of web project.
all the required information like adding the folders eq. global assembly folder etc

all the information
please 1/14/2008 12:03 AM | chetan

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Hi Harish,
I am using "Web Setup Deployment - Creating an installer file", everything is working fine.
Even MSI is created successfully and installing is also successful.
But only one issue is that all code behind files are also present in installed folders.
How can i avoid it or is there any other way to do it.
Please help me.

Thanks in advance.

Regards,
Viswak Parthiban O K 2/13/2008 2:47 AM | Viswak Parthiban O K

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

hi,
Thanks a lot to give the step. but i didn't get the .msi file.please help me how will i create the setup and how will i do the testing. 2/26/2008 11:26 PM | tarique merajul haque

# websetup deployement-creating an Installer File

I have choosen the method of installer file,
and successfully installed the package but the problem here is .. i am trying to run the application on the intranet but during this i got two errors ..
1.con.open (when i choose the custom error="off")//ie. in opening the connection with the sqlserver 2000 and
2. if custom error ="on/remote only" then in web.confin file i got ..
custom error mode ="remote only"
if someone can sought it out plz tell me the right way
thank you
3/2/2008 10:30 PM | mihika

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Hi
I am using "Web Setup Deployment - Creating an installer file", everything is working fine.
Even MSI is created successfully and installing is also successful.
But only one issue is that all code behind files are also present in installed folders.
How can i avoid it or is there any other way to do it.
Please help me.

Thanks in advance.

Regards,
Arun 5/1/2008 5:58 AM | Arun

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

Hi there

It's a very good article and you expalined almost everthing Thanks.

I finished developping a website and i used Copy Website method . When i upload them to the website using ftp it always shows me the Error

"Compiler Error Message: CS0246: The type or namespace name 'PrtClass' could not be found (are you missing a using directive or an assembly reference?)"

now i lost about 2 days trying to figure out what to do and how to fix this error .

some details:
1- when i want to add new class it force me to add it under app_code and i obey :).

2- i put all of the project under one namespace .

3- the classes that i'm using it's a simple .cs clasees with no dll files to refference.

now what should i do ? Thank you very much

www.dalelkonline.com/aa/names.aspx

this is a dummy site i created to test this problem .

Asaad Mamoun 5/20/2008 12:52 AM | Asaad Mamoun

# re: ASP.NET 2.0 Deployment - Deployment Options and choosing the right one for your need

I am creating a MSI file using websetup project in vs2005. I am also using the Web Deployment project to create a single assembly.
It is taking a lot of time while packaging files into MSI file. I do not know why it is happening.
Can you please help me out ? 5/20/2008 11:57 PM | Tarun Jain

# How do I make a website live?

By live, I mean where it can be accessed on the internet.

I am an old Windows Application developer. When I started my current job as a windows application developer, I inherited an existing website. Over the past five years I have worked on my this website. I have no problem building web applications for this website.

My problem is, the site had already been set up before I got here. My predissesors left no notes or instructions on what they did. I would like to know how it’s done. How does it go from the web server out to where it is accessed on the internet? Is it something I need to by a book for?

I would like to move my website from our old server to the new one. I would also like to upgrade it from .net 2002 to .net 2005, but those are other topics.

Robert 6/12/2008 9:23 AM | Robert

Post a comment





 

Please add 5 and 8 and type the answer here: