MSDN Library

Walkthrough: Deploying a Web Application Project Using a Web Deployment Package (Part 2 of 4)

This is the second in a series of walkthroughs that illustrate how to deploy a Web application project by using a deployment package. For more information about the series, see Walkthrough: Deploying a Web Application Project Using a Web Deployment Package (Part 1 of 4).

In this walkthrough you change the AdventureWorksLT database and deploy the changes. You then change a Web page and deploy those changes, but without deploying database changes. This walkthrough illustrates the following tasks:

  • Redeploying a database that has already been deployed.

  • Excluding from deployment a database that has already been deployed.

  • Creating a package for the Debug build configuration.

  • Installing a package on the local computer by using IIS Manager.

If you want to deploy a database change (either structure or data) to a Web application that has already been deployed, and if you do not have to preserve data that has been entered in the deployed database, you can redeploy the database by using automatically generated scripts. However, by default, automatically generated scripts do not drop database objects before creating (or re-creating) them on the destination computer. Therefore, you must specify that Drop statements should be included in order to avoid errors that would result when scripts try to create database objects that already exist.

In this section of the walkthrough, you make a change to the structure of the AdventureWorksLT database. You then redeploy the Web application. You change database deployment settings so that the automatically generated scripts for the AdventureWorksLT database include Drop statements, and so that no other database scripts run during deployment.

In the following procedure, you change the name of the Color field to Appearance in the database and in the Default.aspx file.

To change the name of a database field

  1. In Server Explorer, expand the App_Data folder and double-click AdventureWorksLT2008_Data.mdf.

    The database opens in the Server Explorer window.

  2. In Server Explorer, expand the Tables folder.

  3. Right-click the Product (SalesLT) table and then click Open Table Definition.

  4. Change the name of the Color column to Appearance, as shown in the following example:

    Database table properties windows
  5. Save the table and close the Table Definition window.

  6. Open the Default.aspx file.

  7. In the GridView control, find the BoundField element for the Color column, and change the value of the DataField, SortExpression, and HeaderText properties from Color to Appearance, as shown in the following example:

    <asp:BoundField DataField="Appearance" HeaderText="Appearance"
        SortExpression="Appearance" />
    
  8. Save and close Default.aspx.

  9. Press CTRL-F5 to test the changes.

    The home page is shown, The Color column has been renamed to Appearance, as shown in the following illustration:

    Adventure Works home page with Appearance column

In the following procedure, you configure deployment so that it generates Drop statements for the AdventureWorksLT database. You must modify the project file to do this, because the setting is not available in the Visual Studio UI.

To specify that Drop statements should be included

  1. In Solution Explorer, right-click the project and then click Open Folder in Windows Explorer.

    A Windows Explorer window is opened to the project folder.

  2. Open AdventureWorks.csproj or AdventureWorks.vbproj using a text editor such as Notepad.

  3. Find the PropertyGroup element that is for the Debug build configuration and AnyCPU platform.

    This element contains the settings that you entered on the Package/Publish Web and Package/Publish SQL tabs in the Properties setting for the project.

  4. In the PropertyGroup element, find the ObjectGroup element that has the name AWLTConnectionString-Deployment.

    This element contains the settings on the Package/Publish SQL tab that pertain to the AdventureWorksLT database.

  5. In the ObjectGroup element, add a ScriptDropsFirst="True" attribute to the PreSource element that is in the first Object element.

    The following example shows the PropertyGroup element that contains the changed PreSource element. (Some of the details in the element in your project file will differ slightly from this example.)

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
      ...
      <PublishDatabaseSettings>
      ...
        <Objects>
          ...
          <ObjectGroup Name="AWLTConnectionString-Web.config" Order="2">
            <Destination Path="..." />
            <Object Type="dbFullSql">
              <PreSource Path="..." ScriptSchema="True" 
                ScriptData="True" CopyAllFullTextCatalogs="False"  
                ScriptDropsFirst="True"/>
              <Source Path="..." Transacted="True" />
            </Object>
            <Object Type="dbFullSql" Enabled="True">
                <Source Path="...AdventureWorksGrant.sql" 
                  Transacted="True" />
            </Object>
          </ObjectGroup>
        </Objects>
      </PublishDatabaseSettings>
    </PropertyGroup>
    
  6. Save and close the AdventureWorks.csproj or AdventureWorks.vbproj file.

  7. If you see a File Modification Detected dialog box, as shown in the following illustration, click the Reload button.

    File Modification Detected dialog box

In the following procedure, you specify that the database scripts should not run. This includes the automatically generated script for the ApplicationServices database and the AdventureWorksGrant.sql script.

To specify that no other scripts should run during deployment

  1. On the project Properties page, click the Package/Publish SQL tab.

  2. In the Configuration list, make sure that Active (Debug) is selected.

  3. In the Database Entries grid, make sure that the ApplicationServices-Deployment row is selected.

  4. In the Database Scripts grid, clear the Include check box for the row that has [Auto-generated Schema and Data] in the Script path column, as shown in the following illustration:

    Package/Publish SQL tab with script excluded
  5. In the Database Entries grid, select the AWLTConnectionString-Deployment row.

  6. In the Database Scripts grid, clear the Include check box for the row that has the AdventureWorksGrant.sql script.

  7. Save and close the Properties page.

In the following procedure, you deploy the project by creating a package and then importing the package into IIS by using IIS Manager.

To create a package and import it into IIS

  1. In the Project menu, click Build Deployment Package.

    Visual Studio builds the project and then creates the deployment package. Scripts that contain Drop statements are created for the AdventureWorksLT database. No scripts are created for the ApplicationServices database.

  2. Copy the path of the deployment package to the Windows Clipboard by following these steps:

    1. In Solution Explorer, if you do not see the obj folder, click the Show All Files button.

    2. Expand the obj folder, expand the Debug folder, and then expand the Package folder.

    3. Select the AdventureWorks.zip file.

    4. In the Properties window, copy the value of the Full Path field.

  3. In the Windows Control Panel, click Administrative Tools, and then click Internet Information Services (IIS) Manager.

  4. In the Connections panel of IIS Manager, expand the node for your computer, expand the Sites folder, and then select Default Web Site.

  5. In the Actions panel, click the Import Application hyperlink.

  6. In the Package path box of the Select the Package dialog box, paste the deployment package path.

  7. Click Next.

  8. In the Select the Contents of the Package dialog box, click Next.

  9. In the Enter Application Package Information dialog box, click Next.

  10. In the Overwrite Existing Files dialog box, click Next.

    After package installation is finished, the Installation Progress and Summary dialog box shows that only one database was updated, as shown in the following illustration:

    Installation Progress and Summary dialog box
  11. Test the application by opening a browser and going to the following URL:

    http://localhost/AdventureWorks

    The Default.aspx page is displayed. It looks the same as it does when you ran the project in Visual Studio. The table of products displays an Appearance column instead of a Color column. This demonstrates that the AdventureWorksLT database change was deployed successfully.

Database structures are typically changed less frequently than other parts of a Web application. In this section of the walkthrough you change a Web page and redeploy the Web application, but you do not deploy database changes.

In the following procedure, you change the heading of the first column in the AdventureWorksLT product table on the Default.aspx page from Name to Product.

To make a change to the application

  1. Open the Default.aspx file.

  2. Change the BoundField.HeaderText property for the Name column to Product, as shown in the following example:

    <asp:BoundField DataField="Name" HeaderText="Product" 
      SortExpression="Name" />
    
  3. Save and close the file.

In the following procedure, you change database deployment settings to make sure that Visual Studio does not generate any database scripts.

To disable database deployment

  1. Right-click the project in Solution Explorer and then click Properties.

  2. Select the Package/Publish Web tab.

  3. Clear the Include all databases configured in the Package/Publish SQL tab check box.

  4. Save and close the Properties page.

In the following procedure, you redeploy the application and test your changes.

To redeploy and test the application

  1. In the Project menu, click Build Deployment Package.

  2. Copy the deployment package path to the Windows Clipboard.

  3. Run Internet Information Services (IIS) Manager.

  4. In IIS Manager, select Default Web Site.

  5. In the Actions panel, click the Import Application hyperlink.

  6. In the Package path box of the Select the Package dialog box, paste the deployment package path.

  7. Click Next.

  8. In the Select the Contents of the Package dialog box, click Next.

  9. In the Enter Application Package Information dialog box, click Next.

  10. In the Overwrite Existing Files dialog box, click Next.

    This time, the Installation Progress and Summary dialog box shows that no databases were updated and only one file was updated.

  11. Test the application by opening a browser and going to the following URL:

    http://localhost/AdventureWorks

    The Default.aspx page again looks the same as it did when you ran it in Visual Studio. The heading Product in the first column of the table of products demonstrates that the change to Default.aspx was deployed successfully.

In the first walkthrough in this series, you deployed a file-system Web application project to an IIS Web application in order to test it on the development computer. In this walkthrough, you changed the structure of one of the databases, changed Web pages, and deployed the changes.

The next walkthrough in the series is Walkthrough: Deploying a Web Application Project Using a Web Deployment Package (Part 3 of 4). In that walkthrough, you create a deployment package that can be used to deploy to a staging environment and to a production server.

Community Additions

Show:
© 2016 Microsoft