Exercise 2: Transforming a Web.Config File for Deployment
Generally, a web application goes through a chain of environments before it makes it into a Production environment. Some of these environments are Development (the developer’s local machine), Quality Assurance (QA), and User Acceptance Testing (UAT) / Staging / Pre-Production. As applications transition through these environments, various settings in the configuration files must change. In addition to database connection strings, many Enterprise scale applications also rely on configuration settings for logging destinations, file drop shares and addresses for service endpoints.
Visual Studio 2010 adds a new Web.config transformation model that you can use to automate changes to the Web.config file during the deployment of the application when you use MSDeploy to promote your code.
To complete the tasks in this exercise, you must have completed all the tasks in Exercise 1, or use the solution from the %TrainingKitInstallFolder%\Labs\WebDevelopment\Source\Ex02-TransformingWebConfig\begin\C#\HTMLLab folder.
Task 1 – Creating a Staging Configuration in Visual Studio 2010
Task 2 – Adding Code to Populate Text Value of EnvName from a Value in the Web.config
Before we start this task, you will need to add a label to the Default.aspx page to contain an environment variable. Here’s what the label should look like when you are done.
Label in Default.aspx
In this task, you will add functionality to take the environment name from the Web.config file and populate the text attribute of the label.
Task 3 – Adding a Logging Database Connection String to the Web.config File
In this task, you will add a connection string to logging application messages to the database.
Task 4 – Writing a Transform to Change the Environment and Logging Connection Strings in the Staging Web.config
In this task, you will create a transformation to update Web.config sections when the application is deployed with MSDeploy. In the Web.config file you will update the value of the Environment to “Staging” and change the server name value in the connection string to reflect QA server.
Task 5 – Generating a Transformed Web.config File from the Command Line
In this task, you will use the MSBuild command line tool to create a build and transform the Web.config file based on the Staging configuration as part of the build process.
Task 6 – Generating a Transformed Web.config File from Visual Studio
In this task, you will use Visual Studio to create a build to transform the Web.config file as part of that build.