Udostępnij za pośrednictwem


Walkthrough: Deploying a Web Site Project by Using the Copy Web Site Tool

This walkthrough shows you how to use the Copy Web Site tool to copy files between the Web site project that you have open in Visual Studio and another Web site.

During this walkthrough, you will learn how to do the following:

  • Copy files between Web sites.

  • Synchronize two Web sites so that they have the same version of each file.

    Manage updates between a Web site that multiple developers work on and your copy of the Web site that you are working on.

If you were deploying a site to production, you might want to prevent the production site from responding to page requests during the deployment process; this can help avoid errors that might result because changes are in progress. Also, you might want to make sure that the application domain does not recycle multiple times during deployment. This walkthrough does not cover these tasks. For more information, see How to: Prepare to Deploy a Web Project.

Note

This topic applies only to Web site projects. For information about the difference between Web application projects and Web site projects, see Web Application Projects versus Web Site Projects.

Prerequisites

In order to complete this walkthrough, you will need the following:

  • Visual Studio or Visual Web Developer Express.

    Note

    This walkthrough assumes that you selected the Web Development collection of settings when you started Visual Studio the first time. For more information, see How to: Select Web Development Environment Settings.

  • Access to Microsoft Internet Information Services (IIS) so that you can test the result of publishing a Web site project.

    In this walkthrough, it is assumed that you have IIS running on your own computer. Alternatively, you can use any instance of IIS for which you have permission to create a virtual directory.

Creating the Shared Web Site

In this walkthrough you will work with both a shared and local Web site as you might in a production environment. A typical scenario is that the shared Web site is on another server, such as a staging server or production server. When you want to work on the site, you create a local version of the site, and then copy the files from the shared server to your computer. When you have finished your updates, you copy the local files back to the shared server.

This walkthrough will also let you see what it might be like to work in an environment where there is more than one developer. If there were other developers working on the site, they might also download files, edit them locally, and then copy the files back to the shared server. Therefore, not only must you copy files from the local Web site to the shared Web site, but you also might have to copy updated versions of files on the shared Web site to the local Web site.

The walkthrough emulates this scenario by having you create two Web sites. Instead of residing on separate computers, the Web sites both reside on the local computer. This lets you work with the Copy Web Site tool as you would in a production environment but without requiring you to use a second computer. All tasks that you perform in this walkthrough work identically when the shared Web site is on another computer. You will emulate the edits made by other developers by using Notepad to change files in the shared Web site.

To create a file system Web site

  1. Open Visual Studio.

  2. On the File menu, click New Web Site.

    The New Web Site dialog box appears.

  3. In the list of templates, click ASP.NET Empty Web Site.

  4. In the left-most Web Location list, click File System, and then in the right-most Web Location list, enter C:\SharedWebSite.

    Note

    Procedures later in the walkthrough assume that you are working with a Web site named SharedWebSite.

  5. Under Installed Templates, click the programming language that you prefer to work in.

  6. Click OK.

    Visual Studio creates a Web site project that has only a Web.config file.

Creating Test Pages

For this walkthrough, you will create some simple pages with known names.

To create test pages

  1. In Solution Explorer, right-click the name of the Web site project, and then click Add New Item.

  2. In the list of templates, click Web Form.

  3. In the Name box, type Services.aspx.

  4. Under Installed Templates, click the programming language that you prefer to work in.

  5. Click Add.

    The new page appears in the editor.

  6. Switch to Design view.

  7. In the page, type Services, highlight to select the text that you just entered, and then on the Formatting toolbar, click Heading 1 <h1>.

  8. Position the pointer at the end of the text.

  9. Press ENTER to create a new paragraph, and then type This page lists the services that we offer.

  10. Save the page.

  11. Repeat the steps that created Services.aspx to create a page named Products.aspx with a heading of Products and the text This page lists the products that we sell.

  12. Repeat the steps again to create a page named Default.aspx with a heading of Home and the text Welcome to our Web site.

Now you will add controls on the home page (Default.aspx) to link to the pages that you just created.

  1. Open the Default.aspx page and switch to Design view.

  2. From the Standard group in the Toolbox, drag a Hyperlink control onto the page.

  3. Set Text to Products and NavigateUrl to ~/Products.aspx.

  4. Drag another Hyperlink control onto the page, and then set Text to Services and NavigateUrl to ~/Services.aspx.

  5. Save your files.

Testing the Web Site

Now you will test that the Web site works as you expect.

To test the Web site

  1. In Solution Explorer, right-click Default.aspx, and then click View in Browser.

    The page appears in the browser.

  2. Click Products and Services to confirm that the links work.

  3. Close the browser.

Creating the Source Web Site

In this part of the walkthrough, you will create a second Web site that you can use to copy files to and from. As explained in "Creating the Shared Web Site," earlier in this walkthrough, both Web sites are on your computer, but the first Web site functions as the shared Web site. The Web site that you will create in this part of the walkthrough functions as the site that you would use to edit files.

To create the source Web site

  1. On the File menu, click Close Project to close SharedWebSite.

  2. On the File menu, click New Web Site.

  3. In the list of templates, click ASP.NET Empty Web Site.

  4. In the left-most Web Location list, click File System, and then in the right-most Web Location list, enter C:\LocalWebSite.

  5. Click OK.

Copying Files from the Shared to the Local Web Site

At this point, a shared Web site exists on your computer and you have a new Web site open. If you were a new developer on a project, you would first want to obtain all files from the shared Web site and copy the files to your local Web site.

To copy all files from the shared Web site to the local Web site

  1. On the Website menu, click Copy Web Site.

    The Copy Web Websitename window appears.

  2. Click Connect.

    The Open Web Site dialog box appears.

  3. Click File System.

  4. In the Folder box, type C:\SharedWebSite.

    If the shared site were on another computer on your internal network, you could browse to that folder or enter its address. You could also open a Web site that is on another computer by using HTTP or FTP protocol and entering a URL.

  5. Click Open.

    The files from the shared site are listed under Remote Web Site.

    Many of the files have symbols next to them that indicate their status. The arrow symbol shows you the direction that a file will be copied if you synchronize the sites. Currently, the Services.aspx and Products.aspx files in the Remote Web Site list point to the Source Web Site list, because if you synchronize the Web sites, the Services.aspx and Products.aspx files will be copied from the shared site to the local site.

    The Default.aspx files have question marks (?) next to them. This indicates that the file has the same name in both sites, but different timestamp data and no information about the last time the files were copied. If you synchronize the Web sites, these files will not be automatically copied. Instead, for each file, a dialog box is displayed that provides three options: copy the file from source to remote, copy it from remote to source, or do not synchronize it.

  6. Under Remote Web site, select all files and folders.

    In this case, you want to obtain copies of all files from the shared site. You are emulating a scenario where you are a new developer on an existing Web site and you want to obtain the most current versions of the Web site files. Because you have created a new local site, you do not have to copy any files from the local site to the shared site.

  7. Click the left-arrow button to copy the selected files from the shared site to the local site.

    The left-arrow button is not labeled unless you move the pointer over it, in which case a tooltip appears. The arrow is pointing to Source Web Site.

    Visual Studio starts copying files. When it gets to the Default.aspx file, it prompts you for confirmation to overwrite the local copy of the file with the file from the shared site.

  8. In the Confirm File Overwrite dialog box, select the Apply to all check box, and then click Yes.

    In this case, it is safe to overwrite all local versions of any files that have duplicated file names, because you want the file versions from the shared site. When the copy process is finished, the lists in Source Web Site and Remote Web Site are the same.

    Note

    The Copy Web Site tool does not merge files, it only overwrites files.

  9. Close the Copy Web window.

Copying Individual Pages

You can use the Copy Web Site tool to copy all files or individual files. In this part of the walkthrough, you will create a new Web page in the source Web site, and then copy the new Web page file to the shared Web site.

To create and copy an individual file

  1. In Solution Explorer, right-click the name of the Web site, and then click Add New Item.

  2. In the list of templates, click Web Form.

  3. In the Name box, type Extra.aspx.

  4. Click Add.

    You do not have to add any content to the page.

  5. Close the page.

    The new page is displayed in Source Web Site with arrows next to it pointing to Remote Web Site. If you synchronize right now, the files will be copied from the local Web site to the shared Web site.

  6. In the Copy Web Websitename window, select the new file or files.

  7. Click the right/left-arrow button to synchronize the selected files.

    The new page is copied to the shared Web site and the list in Remote Web Site is updated.

Synchronizing Web Sites

Synchronizing means copying the most current version of each file so that both Web sites have the same copies of all files. Use synchronization if the files on the shared Web site might be updated by someone other than you. In this part of the walkthrough, you will first change both the local and shared Web site, and then you will synchronize the changes between the sites.

To change the local and shared Web sites

  1. In the Copy Web Websitename window, under Source Web site, select Extra.aspx and then click the delete button.

  2. When you are prompted for confirmation to delete the file, click Yes.

    The files for the deleted page appear in Source Web Site with a symbol next to them that indicates that the files have been deleted.

    Note

    Make sure that the Show deleted files since the last copy operation check box is selected.

  3. In Windows, start Notepad, and then open C:\SharedWebSite\Products.aspx.

  4. Add extra spaces or other characters to the file, save the file, and then close Notepad.

    You are changing the file to emulate what would occur if another developer changed the file on the shared Web site.

  5. In Visual Studio, in the Copy Web Websitename window, click Refresh Remote Web Site.

    An arrow appears next to the Products.aspx file pointing to Source Web Site.

  6. Under Remote Web Site, select all files and folders, and then click the synchronize button to synchronize the selected files between the same relative paths in both LocalWebSite and SharedWebSite.

    This button is not labeled unless you move the pointer over it. The button has a right and left arrow to indicate both panes.

  7. When prompted to delete the Extra.aspx file in the remote Web site, click Yes. This in effect propagates the deletion to the remote Web site.

    The Products.aspx page is copied from the remote Web site to the source Web site.

    Note

    If you selected all files and folders under Source Web Site and synchronized the files and folders, the results would be the same.

Next Steps

This walkthrough has illustrated the basic tasks that you can accomplish with the Copy Web Site tool. Although the Web sites that you worked with contained only a few files, you can apply the techniques that are used in this walkthrough to sites of any size. You might also want to experiment with additional ways to copy files to remote computers. For example, you might want to do the following:

See Also

Tasks

How to: Deploy a Web Site Project by using the Copy Web Site Tool

Other Resources

Deployment for Web Site Projects