If you are developing Web applications with Visual Studio .NET, you can still manually deploy your applications using XCOPY, WebDAV, and so on. However, you will probably find that it is more efficient to take advantage of one of the built-in deployment features available in the Visual Studio .NET IDE. These include the copy project command, which provides a fast and simple method for copying a project from one machine to another or from one directory to another on the same machine, and the Setup And Deployment Projects type, which provides much more fine-grained control over how your application is deployed.
The copy project command, which you access by clicking Project, and then Copy Project (or from the toolbar of the Solution Explorer window), allows you to copy just the files you need to run an application (only the .aspx files and related assemblies, plus any static content; code-behind class files are not copied), all of the files in the project, or all of the files in the source project folder, whether they are a part of the project or not.
You can copy files either to a URL using the Microsoft FrontPage server extensions, or to a file share. The Copy Project dialog box is shown in the following illustration.
The following section describes a feature available only in Visual Studio .NET Professional, Enterprise Developer, or Enterprise Architect editions. This functionality is not available with the Standard edition of Visual C# .NET.
Another method that Visual Studio .NET offers for deploying Web applications is the Web Setup Project, which is one of the templates available in the Setup And Deployment Projects project type. The following illustration shows the Web Setup project selected in the Add New Project dialog box.
A Web Setup project allows you to specify a variety of options about how the application will be deployed, ranging from which files to include to the name of the deployed application and the location of the deployed files. When built, the Web Setup project creates a Windows Installer .msi file that can be copied to the target machine and executed to deploy the application.
Create a Web Setup project in Visual Studio .NET
Open an existing Web application solution in Visual Studio .NET Professional, Enterprise Developer, or Enterprise Architect editions.
Right-click the solution name in the Solution Explorer window, and select Add, New Project. The Add New Project dialog box will appear.
Select the Setup and Deployment Projects type, select the Web Setup Project template, and then click OK to accept the default project name. Make sure that Add To Solution is selected. The File System editor for the Web Setup project will appear.
Make sure WebSetup1 is selected in the Solution Explorer. In the Properties window, modify the ProductName property to match the name of the Web application project you opened in Step 1.
Right-click the Web Application Folder node in the left pane of the File System editor, select Add, and then select Project Output. The Add Project Output Group dialog box will appear, as shown in the following illustration.
Select both the Primary Output and Content Files items from the list. Use the Ctrl key to select multiple items. Click OK.
Select the Web Application Folder node in the File System editor. Then locate the VirtualDirectory entry in the Properties window and change it to the name of a target directory on the deployment target. This directory does not need to exist—it will be created. Specify only a relative path to the virtual directory—do not use drive letters or absolute URLs.
Also in the Properties window, set the DefaultDocument property to the name of the default document for the Web application opened in Step 1.
Right-click the solution containing the WebSetup1 project, and select Configuration Manager.
In the Configuration Manager dialog box, ensure that the Build check box for WebSetup1 is checked. If it is not, check it, and then click Close.
Locate the set-up package created by the Web Setup project. It should be located in the Debug or Release subdirectory of the directory containing the Web Setup project, and will be called WebSetup1.msi if you used the default project name of WebSetup1. Copy the file to the target server and execute it. The following illustration shows the initial screen of the installation program.
When you’ve completed the Setup Wizard, browse the newly deployed application using the URL http://machinename/vdirname/, where machinename is the name of the machine where you installed the set-up package and vdirname is the name that you specified for the VirtualDirectory property in Step 7. If the deployment worked correctly, you should see the default page for the Web application.
The installation created by Visual Studio .NET does not install the .NET Framework. You can run the program dotnetfx.exe in the dotNetFramework folder of the Visual Studio .NET Prerequisites CD before executing the installation package to allow the project to install, if the target machine does not already have the .NET Framework installed.
In addition to providing fine-grained control over the files and outputs included in the installation package, this method allows you to automatically install shared assemblies in the GAC. It also allows you to uninstall a Web application with a single command, either by right-clicking the installation package and selecting Uninstall or by locating the application’s entry in the Windows Add/ Remove Programs applet, which you can access from the Control Panel.