Exercise 4: Packaging and Deploying Web Applications for Internet Information Server (IIS)

In the previous exercise, you deployed a web application to the Visual Studio Development Studio. In this exercise, you will deploy the same web application to IIS. In order to complete this exercise, you will need to launch Visual Studio as Administrator, by right-clicking the Visual Studio 2010 icon in the Start menu and selecting Run as administrator.

To complete the tasks in this exercise, you must have completed all the tasks in Exercise 3, or use the solution from the %TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex04-PackageDeployIIS\begin\C#\HTMLLab folder.

Task 1 – Opening the Project Properties Publish Page, Setting the Web Application to Use IIS and Create a Package.

In this task, you will open the product properties page, set the web application to use IIS and examine some of the features and settings available.

  1. Using Windows Explorer, create a new folder “C:\HTMLLab”.
  2. In Visual Studio, open the properties page for the HTMLLab project by right-clicking the HTMLLab project and selecting Properties from the menu.
  3. Click the Web tab.
  4. In the Server section of the properties page, click the radio button Use Local IIS Web server:

    Figure 40

    Setting web application to use local IIS Server

  5. Click the Create Virtual Directory button to create a virtual directory on the local instance of IIS. You should see a message box notifying that the virtual directory was created successfully.

    Figure 1

    Virtual directory created successfully

  6. Click the Package/Publish Web tab. In the Items to deploy (applies to Web Deploy only) section, notice that Include IIS settings as configured in IIS checkbox is now enabled.

    Figure 42

    IIS settings is enabled

    Checking this box ensures that all of the IIS settings for your web application are packaged by MSBuild.

  7. Make sure that the active configuration is set to Staging.
  8. Check the Include IIS settings as configured in IIS checkbox and the Include application pool settings used by this Web project settings.
  9. Check the Create deployment package as a zip file checkbox. Note the path in the location textbox. This is where the build process will create the package.
  10. Set C:\HTMLLab\ as Destination Application Physical Path

    Figure 43

    Create package as ZIP file and output path

  11. Press CTRL+SHIFT+S to save all the changes.
  12. In the Project menu click Build Deployment Package. In the Output window observe that the build and publish process succeeded.

    Figure 44

    Successful build and publish

  13. Using Windows Explorer, navigate to the relative path in the location textbox referenced above. For example, if you are still using the HTMLLab project from Exercise 1, navigate to the %TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex01-HTMLCodeSnippets\begin\C#\HTMLLab\obj folder.
  14. Note that a folder for the selected configuration (Staging) has been created. Double-click on it. Within that folder, a new folder Package is created. Double-click on Package folder to open it.

    Figure 45

    Packaged web application

    Note that this folder contains the same items as in the previous Exercise.

Task 2 –Deploying the Package

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

  1. Navigate to Start | All Programs | Accessories and click Run. In the Run box type: “inetmgr” and click OK to bring up Internet Information Services Manager.
  2. In the Connections tree view on the left, expand the node for the local machine. Within that node, expand the node for sites.

    Figure 46

    List of local web sites

  3. Expand the Default Web Site node. Verify that the HTMLLab web application is listed (this was created when you clicked the Create Virtual Directory button in the previous task.)

    Figure 47

    HTMLLab virtual directory created

  4. Next you will deploy the application in Trial mode.

    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 Trial mode to see the impact on the server.

  5. Navigate 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.
  6. At the command prompt, change the current directory to C:\Program Files\IIS\Microsoft Web Deploy\ by typing:


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

  7. 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:


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

    Figure 48

    Executing the deployment command batch file in Trial mode

    If you receive the following error after running the previous command:

    The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v2.0'. This application requires 'v4.0'

    Execute the aspnet_regiis.exe –i command from a Visual Studio 2010 Command Prompt with administrator privileges and then try again.

  8. Examine the output of the Trial deployment.

    Figure 49

    Results of the Trial mode deployment

    In this case, you can see that the MSDeploy will make 12 changes to the server.

  9. Execute the deployment by re-running the HTMLLab.deploy.cmd batch file. In this instance remove the /t (trial) flag and replace it with the /y (yes) flag. For example, if you are still using the HTMLLab project from Exercise1, type:


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

    Figure 50

    Executing the deployment command batch file in Yes mode

  10. Examine the output of the deployment.

    Figure 51

    Executing the deployment command batch file in Yes mode

    MSBuild deployed the package to the specified physical location.

Next Step

Exercise 4: Verification