Exercise 3: Packaging and Deploying Web Applications for the Visual Studio Development Web Server

Most web sites need a lot of artifacts and resources to function properly. Deploying all of these correctly is not a trivial task. Visual Studio 2010 contains a new feature which allows you to create a ZIP file called Web Package which is a self-describing entity containing all the assets and resources that should be deployed to the server by MSDeploy.

In this exercise, you will use this new feature to deploy the web application to the VS Development Web Server.

Note:
To complete the tasks in this exercise, you must have completed all the tasks in Exercise 2, or use the solution from the %TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex03-PackageDeployDevServer\begin\C#\HTMLLabfolder.

Task 1 – Opening the Project Properties Publish Page and Creating a Package

In this task, you will open the product properties page and examine some of the features and settings available.

  1. Open project property pages by right-clicking the HTMLLab project and selecting Properties from the menu. Click the Package/Publish Web tab.
  2. Verify that the active build configuration is set to Staging from the build option menu.

    Figure 1

    Verifying the Active Build Configuration

  3. Select the Create deployment package as a zip file option, if it is not already selected. Note the path in Package Location. This is where the package will be placed after it is built.

    Figure 26

    Create package as ZIP file and output path

  4. Using Windows Explorer, navigate to the HTMLLab project directory and then to the obj folder and delete all the content of the folder, if the folder exists.
  5. Select the Project menu and click Build Deployment Package. In the Output window observe that the build and publish process have succeeded.

    Figure 27

    Successful build and publish

  6. Using Windows Explorer, browse to the relative path specified in the package location textbox referenced above. Note a newly created folder for the selected configuration. Double-click the folder. Double-click the Package folder to open it.

    Figure 28

    Packaged web application

  7. Note that this folder contains the following items:

    • HTMLLab.deploy.cmd – It is a batch file generated by Visual Studio to help with the installation of the web application on the destination server.
    • HTMLLab.deploy-readme.txt – contains detailed information about how you can parameterize the deployment using Web Deploy (msdeploy.exe).
    • HTMLLab.SetParameters.xml –This file provides the installation path. By default, this file points to the path specified in the application name to use in the destination server textbox. If you choose to install the package elsewhere, you will need to change the path in this file.
    • HTMLLab.SourceManifest.xml –Visual Studio uses this file internally to create the package. The lab ignores this file.
    • HTMLLab.zip – The deployable web package.
    Note:
    In most situations, you will be deploying your application to a different machine than the one in which you built the package. In those cases, the three files that you will need to move to the target machine are the ProjectName.deploy.cmd, ProjectName.SetParameters.xml, and ProjectName.zip files.

Task 2 – Preparing the Web Server for Deployment

In this task, you will create a new application on the web server to which this application is to be deployed.

  1. Using Windows Explorer, create a new folder “C:\HTMLWebApp”.
  2. Browse to Start | All Programs | Accessories, and click Run. In the Run box type: “inetmgr” and press ENTER to bring up Internet Information Services (IIS) Manager.
  3. In the Connections pane, located on the left, expand the node for the local machine. Within that node, expand the node for Sites. You should now see a list of web sites:

    Figure 29

    List of local web sites

  4. Right-click the Default WebSite and select Add Application.
  5. In the Add Application dialog set the Alias to HTMLWebApp, and the Physical path to C:\HTMLWebApp. Take note of the Physical path as you will be deploying the package there. Click the OK button to close the dialog.

    Figure 30

    List of local web sites

  6. In IIS Manager, right-click the new HTMLWebApp Web Application, point to Manage Application and select Advanced Settings. The Advanced Settings dialog will be displayed.

    Figure 31

    Web application Advanced Settings

    Note that the Application Pool is set to DefaultAppPool.

  7. Select Application Pool, and then click the ellipsis button next to the DefaultAppPool to bring up the Select Application Pool dialog.

    Figure 32

    Select Application Pool

  8. Using the dropdown list box labeled Application pool select ASP.NET v4.0. Click OK to close the Select Application Pool dialog. Click OK to close the Advanced Settings dialog.

    Note:

    Watch Out

    If IIS was not enabled during the Visual Studio 2010 installation you may need to install ASP.NET into IIS by running the following command from a Visual Studio 2010 Command Prompt with administrator privileges: aspnet_regiis.exe –iru. After doing this, you will need to close and reopen IIS Manager to see “ASP.NET V4.0”.

    If you do not see a Deploy menu option it could mean that IIS Web Deployment Tool is not installed or may need to be reconfigured. To fix this you should do the following:

    – Download the IIS Web Deployment tool from https://www.iis.net/extensions/WebDeploymentTool

    – Start the setup

    If setup shows you the Change /Repair / Remove screen, select Change and install the IIS Manager UI module.

Task 3 – Deploying the Package

In this task, you will deploy the package to the web application created in the previous task.

  1. To deploy the package to the earlier specified physical location, you will need to change the HTMLLab.SetParameters.xml file. In Windows Explorer, select the HTMLLab.SetParameters.xml file and open it with Visual Studio. The current file content should appear similar to the following.

XML

<?xml version="1.0" encoding="utf-8"?> <parameters> <setParameter name="IIS Web Application Name" value="Default Web Site/HTMLLab_deploy" /> <setParameter name="LoggingConnectionString-Web.config Connection String" value="Server=(local);Database=Logging;Integrated Security=SSPI" /> </parameters>

  1. Replace the ISS Web Application Name element with the following:

XML

<setParameter name="IIS Web Application Name" value="Default Web Site/HTMLWebApp" />

Note:
The HTMLLab.SetParameters.xml file should be located in the obj\Staging\Package folder of the HTMLLab project.

  1. Click File | Save to save the HTMLLab.SetParameters.xml file.
  2. Next, you will deploy the application in Trial mode.

    Note:
    Trial or What If mode does not actually perform the deployment, but shows you what will happen if you install the package. This is very useful in situations where you are handing off your package to a deployment team or server administrator. The team or administrator can then run the package in What If mode to see the impact on the server.

  3. Browse to Start | All Programs | Microsoft Visual Studio 2010 | Visual Studio Tools. Right-click Visual Studio Command Prompt (2010) and select Run as administrator to open the command prompt.
  4. At the command prompt, change the current directory to C:\Program Files\IIS\Microsoft Web Deploy\ by typing:

    CMD

    cd "C:\Program Files\IIS\Microsoft Web Deploy\"

  5. Execute the HTMLLab.deploy.cmd batch file with the /t (for Trial) flag. For example, if you are still using the HTMLLab project from Exercise 1, type:

    CMD

    "%TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex01-HTMLCodeSnippets\begin\C#\HTMLLab\obj\Staging\Package\HTMLLab.deploy.cmd" /t

    Figure 33

    Executing the deployment command batch file in Trial mode

  6. Examine the output of the Trial deployment.

    Figure 34

    Results of the Trial deployment

    MSDeploy has added five additional files to the specified location.

  7. Execute the deployment by re-running this HTMLLab.deploy.cmd batch file. In this instance remove the /t (trail) flag and replace it with the /y (for Yes) flag by typing:

    CMD

    "%TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex01-HTMLCodeSnippets\begin\C#\HTMLLab\obj\Staging\Package\HTMLLab.deploy.cmd" /y

    Figure 35

    Executing the deployment command batch file in Yes mode

  8. Examine the output of the deployment.

    Figure 36

    Executing the deployment command batch file in Yes mode

    MSBuild has deployed the package to the specified physical location.

    Figure 37

    Deployed web application package

Next Step

Exercise 3: Verification