Walkthrough: Deploying an ASP.NET Web Application Using XCOPY

Deploying ASP.NET applications is very straightforward. You need to copy the application files you have created from your development computer to the production Web server that will host your application. You can use the XCOPY command-line tool or your preferred FTP application to copy the files from one location to another. For more information about general deployment, see .NET Framework Deployment Basics.

Note

As an alternative to using the XCOPY command-line tool, which is supported by all versions of the .NET Framework, you can use the new .NET Framework 2.0 tool located at %SystemRoot%\Microsoft.NET\Framework\version 2 or later\Aspnet_compiler.exe to compile and deploy your Web application. For more information, see ASP.NET Compilation Tool (Aspnet_compiler.exe).

Assemblies that you want to share across Web applications, such as assemblies that contain custom ASP.NET server controls, should be deployed to the global assembly cache (GAC) on a remote server.

If you deploy an application that contains a reference to a custom component registered in the global assembly cache on the local server, the component will not be deployed with the application to the remote server. You will need to install the component in the global assembly cache on the remote server, or you can copy the custom component to the Bin folder of the local Web application before deployment.

For more information, see Global Assembly Cache. For more information about assemblies, see Programming with Assemblies.

Some development tools such as Visual Web Developer have tools that make it easy to deploy your applications. For more information, see Walkthrough: Publishing a Web Site and Walkthrough: Publishing a Web Site and Walkthrough: Deploying a Web Site Project by Using the Publish Web Site Tool.

Prerequisites

In order to complete this walkthrough, you need:

  • The .NET Framework.

  • An existing ASP.NET Web site. If you already have such a site configured, you can use that site as a starting point for this walkthrough. Otherwise, for details on creating a virtual directory or site, see How to: Create and Configure Virtual Directories in IIS 5.0 and 6.0.

  • A destination that is accessible using a file path or UNC path.

Note

This walkthrough does not assume that you are using a designer, such as Visual Web Developer or Visual Studio.

Preparation

Use these procedures if you are deploying a large Web site and you want to take the target Web site offline while you are copying files.

To take a Web application offline before deployment

  1. Create a file called App_offline.htm and place it in the root of your target Web site.

  2. Put a friendly message in the App_offline.htm file to let clients know that you are updating the site.

    While the App_offline.htm file exists, any request to the Web site will redirect to the file.

    Important noteImportant Note:

    Remember to remove the App_offline.htm file after you are finished copying files.

When changes occur to some file types and folders, the application domain restarts. You can configure the number of seconds that the application waits for another file change notification before restarting the application domain.

To minimize the number of times your application domain restarts

  1. Open the Web.config file for you Web application. If you do not have a Web.config file, you can create one using the following code.

    <?xml version="1.0"?>
    <configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.web>
      </system.web>
    </configuration>
    

    For more information, see ASP.NET Configuration Files.

  2. Add an httpRuntime Element (ASP.NET Settings Schema) element to your Web.config file and set the waitChangeNotification attributes to any number of seconds that exceeds the time between the updates of two file-copy change notifications. For example, your httpRuntime element might look like the following code.

    <?xml version="1.0"?>
    <configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.web>
        <httpRuntime 
          waitChangeNotification="5"
        />
      </system.web>
    </configuration>
    
  3. Add a maxWaitChangeNotification attribute to your httpRuntime element and set it to the maximum number of seconds to wait from the first file change notification before restarting the application domain. Set it to a number that exceeds the length of time to complete any file copy processes. File-change notifications are combined based on the value of this attribute and the waitChangeNotification attribute. For example, your httpRuntime element might look like the following code.

    <?xml version="1.0"?>
    <configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.web>
        <httpRuntime 
          waitChangeNotification="5"
          maxWaitChangeNotification="10"
        />
      </system.web>
    </configuration>
    

To deploy an ASP.NET Web application using XCOPY from the command line

  1. Click Start, and then click Run.

  2. In the Open box of the Run dialog box, type cmd, and then click OK.

  3. At the command prompt, type the following command:

    xcopy /I /S <source path> <destination path>
    

    In this command, <source path> is the full path to your Web application, and <destination path> is the full path to the directory where the application will be deployed.

    Note

    You must use the physical directory names with the XCOPY tool. You cannot use virtual directory names.

    The /S parameter copies all subdirectories and the files they contain.

    The /I parameter indicates that a directory is being copied. If the destination folder does not exist, XCOPY creates one.

    The following example command copies all files from the c:\inetpub\wwwroot\devapp directory to the d:\publicsites\liveapp directory.

    Xcopy /I /S c:\inetpub\wwwroot\devapp d:\publicsites\liveapp
    
  4. The command might pause for you to answer a question such as "Overwrite filename (Yes/No/All)?" for which you can type your answer.

    You can exclude subdirectories, which are files with a specific file name extension, or specific file names from being copied by using the XCOPY /EXCLUDE option. For more information and parameters, see Xcopy in the Help and Support window that is available in the Start menu, or type xcopy /? at the command line.

To deploy or update individual files in an ASP.NET Web application from the command line

  1. Click Start, and then click Run.

  2. In the Open box of the Run dialog box, type cmd, and then click OK.

  3. At the command prompt, type the following command:

    xcopy <source path> <destination path>
    

    In this command, <source path> is the full path to the source file that you want to copy, and <destination path> is the full path to the directory where the copied file will be placed.

    The following example command copies a single DLL from a \Bin directory on one drive to a \Bin directory on another drive.

    Xcopy c:\inetpub\wwwroot\devapp\bin\sampleAssembly.dll d:\publicsites\liveapp\bin
    

    The following example command copies all of the DLL files from a Bin directory on one drive to a Bin directory on another drive.

    Xcopy c:\inetpub\wwwroot\devapp\bin\*.dll d:\publicsites\liveapp\bin
    
  4. The command might pause for you to answer a question such as "Overwrite filename (Yes/No/All)?" for which you can type your answer.

See Also

Tasks

Walkthrough: Developing and Using a Custom Web Server Control

Walkthrough: Creating ASP.NET Web Application Root Directories in IIS 6.0

Concepts

ASP.NET Web Site Layout

Other Resources

Creating ASP.NET Web Sites

Deploying .NET Framework Applications

XML Web Services Publishing and Deployment