Hello, in this article i have tried to explain, how a web application is deployed on to web server.
Deployment refers to the process of copying an asp.net web application
from the development system to the server on which the application will
be run. There are several way we can deploy our web application
We can deploy ASP.NET Application in 3 different ways
- xCopy Deployment
- Precompiled Deployment
- Web Setup Project
The choice of best deployment alternative depends upon particular need of each application. Xcopy deployment is the most easiest, and it is often used during development to create copies of an application n different servers for testing purpose. For small application xcopy deployment may be the best choice.
Precompiled deployment has several advantages over XCopy deployment. Eg. Precompiled deployment is always gives better performance for the first users of the site at the same time it is more secure as we don’t need to copy our source code files on to server. If our application deployed on one or few servers then precompiled deployment is usually best choice.
When we are going to deploy our application on number of servers then creating a setup program is a very handy tool. Although creating this setup program is much tedious and involves considerable working, the deployment from this setup program becomes very easier.
To manually copy the files of an asp.net web site to a server. We can use the xcopy command from a command prompt. Then we can use IIS’s (Internet Information Serve management console t o create a virtual directory that’s mapped to the directory that you copied the web site to.
It is easier to create a batch file for the xcopy command. Then after we can run that batch file at given time we make changes to the application and want to deploy the updated code.
We can also perform xcopy deployment from visual studio by using copy website command.
To perform xcopy we use copy web site command. This command lets us to copy website to file system, local IIS, FTP or remote IIS website. At the same time we can copy all or selected files.
How to use this command
- In visual studio open the website to be deployed and choose the website copy web site command.
- Then click the connect button to display an open website dialog box that lets to choose the destination to copy the web site to.
- Click the arrow buttons to copy the files from the source web site to remote web site.
Publish Web Site
The publish web site command lets us to precompile an asp.net application and copy the precompiled assemblies to a target server. This is the easiest way to use the precompiled deployment feature.
- Deploys precompiled assemblies to the specific server
- Lets us to deploy the web site without source code files
- It is done either from publish web site command or from command prompt using the aspnet_compiler command
- Avoids delays caused by compiling web pages when they are first accessed by a user.
- Finds compile errors before the site is deployed.
- Can copy just executable files and not the source files to the server.
The build -> publish web site command compiles all of the files makes up an asp.net application, and then deploys the compiled assemblies to the location we specify.
Publish Web Site
If we check allow precompiled site to be updatable box, the source files are deployed along with the executable files. If we uncheck then source code files aren’t deployed.
The syntax of aspnet_compiler command
The aspnet_compiler command is located in the asp.net framework directory,
aspnet_compiler –v virtual-directory [-u] [-d] [-f] [target-directory]
- -v name of virtual directory of existing web site
- -u precompiled website will be updated
- -d debug information is included in compiled assemblies
- -f overwrite target directory if exist
Precomplies existing website
Aspnet_compiler –v test d:\test
In same place
Aspnet_complier –v test
With debugging information
Aspnet_compiler –v test –u –d d:\test
If we specify target directory the precompiled web site is stored in the specified directory else the website is precompiled in place
- It uses a web setup project to build a windows setup program used to deploy website onto server.
- Useful for deployment on multiple servers.
- Can be used to deploy precompiled assemblies and can be configured to include or omit the source code.
- The installed application can be removed by using add or remove programs dialog box from control panel
How to create a setup
Choose the file -> add -> new project command to display the add new project dialog box. Then, choose setup and deployment. Select web setup project as template, enter a name for websetup project click ok.
Add project to Out put Group
In the solution explorer right click the web setup project and choose the add-> project output command to display the add project output group dialog box, then click ok to add the content files from you website to the web setup project
Use the buttons that are displayed at the top of the solution explorer when web setup project is selected to access setup editors that lets us to customize various aspects of the web setup project.
Add setup prerequisites
Visual studio creates files named setup.exe and setup.msi. setup.exe is the file we will run to install the application and setup.msi contains all of the files to be installed.
The setup.exe and setup.msi files are stored in the web setup project’s debug or release folder.