We have several options to deploy the Asp.Net website.
In this article I am explaining one of the best methods to deploy IIS based Asp.Net website.
Deployment of Asp.Net website involves compiling the code first and directing the compiled output to the special directory from which it may be copied to the deployment machine.
To compile Asp.Net site we have aspnet_compiler compiler in .Net Framework.
aspnet_compiler –v virtualDirectory compilerTarget
The above command will gives the compiled output for our Asp.Net website.
Here virtualDirectory is the virtual directory for our Asp.Net website in IIS and compilerTarget is the path to store compiled output of our site.
Eg. aspnet_compiler –v samplesite C:/SampleSetup
Where samplesite is the virtual directory for our site in IIS and compiled output will save at C:/SampleSetup folder.
Note: If you don’t want to use virtual directory, you can use file location in the place of virtual directory but we have to mention –p after –v.
The command to compile Asp.Net website by mentioning file location is as shown below.
aspnet_compiler –v –p FilelocationOfSite compilerTarget
Eg: aspnet_compiler -v –p E:/SampleSite C:/SampleSetup
Where E:/SampleSite is the path for our Asp.Net website and compiled output will save at C:/SampleSetup folder.
->Create asp.net website by clicking File-> Create New Website and name it as SampleSite.
->Add some content to this website and create virtual directory as samplesite pointing to this site in IIS.
->Now, compile the site for deployment by executing following command in visual studio command prompt.
aspnet_compiler –v samplesite C:/SampleSetup
Where samplesite is the name of virtual directory and compiled output will save in C:/SampleSetup folder.
By executing the above command in command prompt result will be as shown below.
->Add a second project to the solution. Make it a Web Setup Project, as shown in the following image. Name the project SetupforWeb.
->Visual studio will generate new setup project for you. Now you have to add web files to the Application folder.
->Right-click on the Web Application Folder to add the Web files. Navigate to the target directory containing the site code. This will be the compile directory(for my site it is C:/SampleSetup).
->Add the Web files from the compile directory as shown below.
->Add the dlls to the bin directory by right-clicking on the bin node to get the File Open dialog box. Then search for assemblies in the target directory's \bin directory as shown below.
Now you have to deploy the setup. Right-click on the SetupforWeb project and select Build. The resulting MSI file goes in the debug directory of the SetupforWeb folder.
-> Now run the Microsoft Installer file (the MSI file). The MSI file will guide you through several steps as it installs the Web site.
->After Installation completion browse for the website like http://localhost/virtualdirectory/pagename
For me it is like http://localhost/SetupForWeb/default.aspx.
In this way you can install your website on any machine which has IIS to be installed by installing MSI file.
You can download code for this article by using below link.