ARTICLE :
 

Create ASP.NET deployment package using Web Deployment and Web Setup project (MSI installer)

by SBajra on June 15th, 2011

Introduction

This article is to explain how to create MSI installer package from pre-compiled ASP.NET application for server deployment using Microsoft Installer. MSI package provides user friendly wizard like installation steps for application deployment. We can tap in some of the Microsoft Installer feature to deploy Web Application as well. For this, we need to utilize Microsoft Visual Studio "Web Deployment" project template and "Web Setup" project template.

Background

Normally, we can just copy the entire ASP.NET application to the production server as a part of deployment and then ASP.NET framework during runtime will do just-in-time compilation of the web application and executes it. But sometime we don't want to publish our source code especially when we have our application in shared hosting environment. We may just want to just deploy our pre-compiled application to the server so that source code is not available in the server. On top of pre-compiled application, may be get little fancy and use wizard like Windows installer for installing pre-compiled ASP.NET application. When you use Windows installer for installing web application, it even adds application entry to Windows Add/Remove application list in Control Panel which gives nice inventory of installed application in the server and could be uninstalled easily as well. This article explains how we can pre-compile ASP.NET web application and create wizard like Windows Installer for the web application.

Detail

There are three core pieces of this MSI creation puzzle.
1) The ASP.NET application itself.
2) The Web Deployment project.
3) The Web Setup project.

I normally keep all three under one solution so that I can view all three at the same time.


First of all, I assume you have some kind of ASP.NET application or if not create ASP.NET application. Then we will pre-compile the ASP.NET application using Microsoft Web Deployment project. Finally, we will use MS Visual Studio Web Setup project template to create MSI installer package from pre-compiled website. Simple, isn't it?

As I mentioned earlier, for this article I will be using MS Web Deployment project. So, I want to cover quick history on Web Deployment project. I would say Web Deployment project template for MS Visual Studio is kind of funny. It wasn't initially part of Visual Studio 2005 but later Microsoft made it available as extension/plugin from Microsoft site. However, later Microsoft thought it was really helpful template and included in Visual Studio 2008 default installation. But with 2010, Microsoft removed this template again from default installation and made it as extension.

So, if you have visual studio 2005, you would need to download Web Deployment project extension for Visual studio 2005 from Microsoft site.
URL: http://download.microsoft.com/download/c/c/b/ccb4877f-55f7-4478-8f16-e41886607a0e/WebDeploymentSetup.msi

More info on Web Deployment project:
http://msdn.microsoft.com/en-us/library/aa479568.aspx

If you are using Visual Studio 2008, you are all good. It's included in the default installation of Visual Studio 2008.

If you are using Visual Studio 2010, you need to download Web Deployment template as Visual studio 2010 extension.
URL: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=711a2eef-b107-4784-9063-c978edc498cd

First install Web Deployment extension for Visual Studio 2005 / 2010 as we will be using Web Deployment project later in this article.

Scenario:
Let's assume we have an ASP.NET application and we are trying to create executable MSI package from pre-compiled ASP.NET application so that we can easily deploy to any server with few clicks as any Windows application. This also adds benefit of adding the web application into Windows Add/Remove application list in Control Panel.

Detail Steps:
1) Let's start with the creation of Web Deployment project. I assume we have ASP.NET web application already in place. In my example, I have my web application configured as "ASP.NET WebSite". You can also configure your web application as "ASP.NET Web Application" in Visual Studio.

To add Web Deployment project, right click on the "WebSite" in your Visual Studio "Solution Explorer" and click "Add Web Deployment Project". This option will be available only if you have Web Deployment project installed.



Enter your Web Deployment project "Name:" and physical file location "Location:" and click "OK".

2) So far we have our WebSite and WebDeployment projects under the solution. Now, its time to add 3rd project which is "Web Setup" project. This project actually creates MSI package. To add Web Setup project, right click on the solution in Solution Explorer and click "Add" then "New Project". Then, select "Web Setup Project" from Visual Studio project templates list. "Web Setup Project" will be available under "Setup and Deployment", which in Visual studio 2010 is under "Other Project Types".


Provide the name for your Web Setup project and physical file location. For this article, I am going to leave everything to default and click "OK".

3) Now we should see 3 projects in Solution Explorer – the WebSite, Web Deployment project and Web Setup project.


4) Now, lets define the "Project Output" for the Web Setup project we just added. Right click on Web Setup project and click Add>Project Output.


Now you will see "Project Output" dialog box. Project Output defines what output you want to include in your MSI package. In our case, we want output of pre-compiled website generated by Web Deployment project. So, select Web deployment project from "Project:" dropdown as your output project name and and select "Precompiled Web Outputs" from the listbox and click "OK".


This will add "Precompiled Web Outputs" to the Web Setup project. This means, installation content for our Web Setup project is precompiled output of Web Deployment project.


5) Now, lets configure "Project Dependencies". "Project Dependencies" will set dependency or order in which each of the projects will get compiled. This will set the priority on how you want to perform your build. Since our main WebSite is not dependent on anything, it should build first. Then it should build WebDeployment project as it only depends on WebSite build. Finally WebSetup project should build, which depends on both WebSite build and WebDeployment build. In this whole process, WebDeployment project will pre-compile the ASP.NET website application which will get packaged into MSI installer by WebSetup project.

WebSite is not dependent on WebSetup or WebDeployment


WebDeployment is dependent on WebSite


WebSetup (which creates MSI) is dependent on both WebSite and WebDeployment.

After setting all these properties, click "OK".

6) Now before we build the entire solution, one last item in the list. We need to configure "Configuration Manager". "Configuration Manager" settings will tell Visual Studio which projects to include during "Release" build and "Debug" build.

To get "Configuration Manager" dialog, right click on the solution in "Solution Explorer" and click "Configuration Manager".


In "Configuration Manager" dialog, include all 3 projects for "Release" build and just include WebSite for "Debug" build. You should normally create MSI package for server deployment only from "Release" build.

For Release build:


For Debug build:


After setting these cofiguration, click close button.

7) Finally, everything is configured properly and now we can build the entire solution by clicking "Build Solution".

If everything goes fine and the build is successful, you will be able to see the MSI package with pre-compiled content of the ASP.NET website under "Release" folder in Web Setup setup project file path.

Conclusion

This is how you can easily create distributable pre-compiled MSI package of your ASP.NET application. In this article, I haven't covered lot of properties of WebDeployment project and WebSetup project to customize the MSI package. However, you can explore all these properties in your leisure time.

Download

Click here to download source code

Author:

Profile Photo
SBajra
Date: June 15th, 2011

Comments:



Profile Photo
Commented by Aya Saleh
on December 19th, 2011 at 08:35:03 EST
Thank you so much for the post (Y)(Y)(Y) It's simple and in well defined steps , It worked for me :))


Profile Photo
Commented by Manoj
on March 15th, 2012 at 02:14:09 EST
HI...

Thanks a lot for the article. Really Helped, i am now able to create a deployment package.

Just want to check if you could help me further on this. The aspx pages deployed in the application directory using the setup show all the HTML code inside it. Is there any way to deploy these pages which do not show this HTML code. It was a functionality provided with the Publish Wizard on VS2003 where the published aspx pages would not include the HTML code inside it, it was rather only display "This is a markup page".

Would really appreciate if you could help me with this.

Thanks
- Manoj

Profile Photo
Commented by SBajra
on April 4th, 2012 at 14:29:00 EST
Hi Manoj,
Its really simple to hide html content from aspx pages using web deployment project.

- right click web deployment project in solution explorer
- click property pages
- Under property pages dialog, under compilation section, uncheck "Allow this precompiled site to be updatable"

I hope this helps.

Profile Photo
Commented by Swee Keng
on April 13th, 2012 at 05:44:43 EST
Hi,

I followed the step to do it, why I can't get the files of "setup.exe" and "websetup1.msi" in Release folder? Please advise. Thanks.

Profile Photo
Commented by Swee Keng
on April 13th, 2012 at 22:21:35 EST
Sorry, please ignore my previous comment. I got it on yesterday already, thanks a lot~ ^^

Profile Photo
Commented by Swee Keng
on April 14th, 2012 at 00:31:02 EST
I face installation problem, when I try to install the web application from the setup file to win XP, the error message prompt out for "Could not open key: Software\Microsoft\ASP.NET\4.0.30319.0. Verify that you have sufficient access to that key, or contact your support personnel."

Any idea?

Profile Photo
Commented by Swee Keng
on April 14th, 2012 at 04:40:02 EST
I fixed it after I change the ASPNETVersion from 4.0 to 2.0. :)

Profile Photo
Commented by Pp Pp
on June 26th, 2012 at 07:20:46 EST
If we run this MSI on fresh m/h (not having IIS and .Net fremwork) then it won't work.
Is there any way by which we can install IIS and .NEt fremwork with this MSI?

Profile Photo
Commented by Pp Pp
on June 26th, 2012 at 07:23:13 EST
If we run this MSI on fresh m/h (not having IIS and .Net fremwork) then it won't work.
Is there any way by which we can install IIS and .NEt fremwork with this MSI?

Profile Photo
Commented by Sumana Ganapathy
on June 28th, 2012 at 01:08:54 EST
Very good article. It helped me a lot.

Please guide me in creating custom actions with MSI installation, like Database connectionstring or any other prerequisites.


Profile Photo
Commented by SBajra
on July 2nd, 2012 at 09:04:50 EST
Adding prerequisite of .NET framework is easy, simply right click the Setup project and click "Properties" which will prompt with a dialog box to enter "Prerequisites...".

If you are looking for any custom prerequisites then you should be able to at least enforce or message appropriately using custom action. When you create Custom action for setup project, you will have "Install" method which you can override with your required behavior.

To create custom action, you need to inherit from Installer class. I have provided a code sample below. this is not complete working work but something to start with.
For example:

namespace Tools
{
/// <summary>
/// Summary description for ProjectInstaller
/// </summary>
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
/// <summary>
/// Constructor
/// </summary>
public ProjectInstaller()
{
components = new System.ComponentModel.Container();
}

/// <summary>
/// Required Method. Calls Base Class to perform installation and
/// implements custom code during install.
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(IDictionary stateSaver)
{
//DO YOUR PREREQUISITE CHECK HERE
//AND MESSAGE APPROPRIATELY OR INSTALL PRE-REQUISITE HERE.

//Required, very important. DOES ACTUAL INSTALLATION
base.Install(stateSaver);

//IF YOU WANT TO DO AFTER THE INSTALLED COPIED THE FILES THEN DO IT HERE
}
}
}

Profile Photo
Commented by Holden Caulfield
on September 25th, 2012 at 11:39:21 EST
How can I access my aspx pages after the msi has been installed ? Thank you :)

Profile Photo
Commented by SBajra
on September 25th, 2012 at 12:09:03 EST
aspx pages are access via IIS after installed. MSI is mechanism to package your asp.net application and provide wizard like interface to deploy.

Profile Photo
Commented by Holden Caulfield
on September 26th, 2012 at 03:46:21 EST
So after, I have to create a site in IIS, and then install the MSI refering this site ? Am I right ?

Profile Photo
Commented by Holden Caulfield
on September 26th, 2012 at 03:49:35 EST
So after, I have to create a site in IIS, and then install the MSI refering this site ? Am I right ?

Profile Photo
Commented by Holden Caulfield
on September 26th, 2012 at 03:49:42 EST
So after, I have to create a site in IIS, and then install the MSI refering this site ? Am I right ?

Profile Photo
Commented by SBajra
on September 26th, 2012 at 08:16:27 EST
Yes, you have to create a Web Site in IIS. And Web Setup project installer will either create new virtual directory and install your files or install at the root of your WebSite in IIS.

Please download the demo that I have included and try it out. hope this helps.

Profile Photo
Commented by Dan Lamprey
on September 28th, 2012 at 09:12:27 EST
Great article. After scouring the web using Google, I found you to have the best reference for this topic!

Do you have any suggestions of how to create a database (MSSQL) or apply updates (scripts) could be included in the MSI?

Also, will you be updating this for VS 2012 (I am not there yet, but probably soon).

Thanks again!!!

Profile Photo
Commented by SBajra
on September 28th, 2012 at 10:51:57 EST
You could do any installation pre-requisites in Custom Action class (Installer class). I posted the sample class in my previous reply.

However, I do not recommend including Database scripts into MSI package because normally database should be created once and should be handled outside your application installation. Normally, we will be deployment MSI packages more often than database changes. So, I suggest to keep database changes outside MSI package but technically you can include into Custom Action.

Profile Photo
Commented by Manish Srivastava
on November 8th, 2012 at 01:38:35 EST
Error:
invalid start-tag
Specification:
http://www.w3.org/TR/REC-xml/#NT-STag
1: <%@ page language="C#" autoeventwireup="true" inherits="_Default, manishsri" %>
2:
3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
4:

this error occur when we run the aspx file from iis


Profile Photo
Commented by SBajra
on November 8th, 2012 at 07:48:19 EST
@ Manish:
Does your application works with IIS without using MSI package?

Your issue seems to be unrelated to packaging to MSI. I suggest you should open a new issue to discuss futher on your issue.

Profile Photo
Commented by Abel Adeb
on November 19th, 2012 at 08:01:21 EST
Good article. It worked. Thanks so much.

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 14:20:22 EST
Hello,
After following the steps, I don't find the .msi in Release folder? Please, help. Many thanks.

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 14:31:16 EST
Hello,
After following the steps, I don't find the .msi in Release folder? Please, help. Many thanks.

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 14:38:11 EST
Hello,
After following the steps, I don't find the .msi in Release folder? Please, help. Many thanks.

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 14:41:31 EST
After building I have the following output. I do not know if its gonna help.
------ Rebuild All started: Project: WebApplication1, Configuration: Debug Any CPU ------
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(54,30): warning CS0168: The variable 'DBInsertException' is declared but never used
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(73,30): warning CS0168: The variable 'DBUpdateException' is declared but never used
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(99,30): warning CS0168: The variable 'DBInsertException' is declared but never used

Compile complete -- 0 errors, 3 warnings
WebApplication1 -> C:\@StillTesting\BIN\Installation V1\WebApplication1\bin\WebApplication1.dll
------ Skipped Rebuild All: Project: E-GenniusAndCSBF Inc Vesrion Betta.csproj_deploy, Configuration: Debug Any CPU ------
Project not selected to build for this solution configuration
------ Skipped Rebuild All: Project: EGenniusAndCSBF ver Betta, Configuration: Debug ------
Project not selected to build for this solution configuration
========== Rebuild All: 1 succeeded, 0 failed, 2 skipped ==========

Please, advise

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 15:44:12 EST
After building I have the following output. I do not know if its gonna help.
------ Rebuild All started: Project: WebApplication1, Configuration: Debug Any CPU ------
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(54,30): warning CS0168: The variable 'DBInsertException' is declared but never used
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(73,30): warning CS0168: The variable 'DBUpdateException' is declared but never used
C:\@StillTesting\BIN\Installation V1\WebApplication1\DBHandling.cs(99,30): warning CS0168: The variable 'DBInsertException' is declared but never used

Compile complete -- 0 errors, 3 warnings
WebApplication1 -> C:\@StillTesting\BIN\Installation V1\WebApplication1\bin\WebApplication1.dll
------ Skipped Rebuild All: Project: E-GenniusAndCSBF Inc Vesrion Betta.csproj_deploy, Configuration: Debug Any CPU ------
Project not selected to build for this solution configuration
------ Skipped Rebuild All: Project: EGenniusAndCSBF ver Betta, Configuration: Debug ------
Project not selected to build for this solution configuration
========== Rebuild All: 1 succeeded, 0 failed, 2 skipped ==========

Please, advise

Profile Photo
Commented by Osvaldo Zandamela
on December 6th, 2012 at 15:51:11 EST
Sorry! I was making mistake on the step 6. On the release build, I did not select debug on the configuration drop down for the Web App

Profile Photo
Commented by Prem Jose
on June 13th, 2013 at 09:17:55 EST
We're unable to generate MSI or EXE file after build, "Installation Incomplete" in Visual studio 2010 ultimate..we're running a web application with Ms Access 2010 64 bit..kindly help to migrate