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.
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.
- Open project property pages by right-clicking the HTMLLab project and selecting Properties from the menu. Click the Package/Publish Web tab.
Verify that the active build configuration is set to Staging from the build option menu.
Verifying the Active Build Configuration
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.
Create package as ZIP file and output path
- 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.
Select the Project menu and click Build Deployment Package. In the Output window observe that the build and publish process have succeeded.
Successful build and publish
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.
Packaged web application
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.
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.
- Using Windows Explorer, create a new folder “C:\HTMLWebApp”.
- 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.
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:
List of local web sites
- Right-click the Default WebSite and select Add Application.
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.
List of local web sites
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.
Web application Advanced Settings
Note that the Application Pool is set to DefaultAppPool.
Select Application Pool, and then click the ellipsis button next to the DefaultAppPool to bring up the Select Application Pool dialog.
Select Application Pool
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.
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 http://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.
- 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 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>
- Replace the ISS Web Application Name element with the following:
<setParameter name="IIS Web Application Name" value="Default Web Site/HTMLWebApp" />
The HTMLLab.SetParameters.xml file should be located in the obj\Staging\Package folder of the HTMLLab project.
- Click File | Save to save the HTMLLab.SetParameters.xml file.
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 What If mode to see the impact on the server.
- 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.
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\"
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:
Executing the deployment command batch file in Trial mode
Examine the output of the Trial deployment.
Results of the Trial deployment
MSDeploy has added five additional files to the specified location.
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:
Executing the deployment command batch file in Yes mode
Examine the output of the deployment.
Executing the deployment command batch file in Yes mode
MSBuild has deployed the package to the specified physical location.
Deployed web application package
Exercise 3: Verification