In all project it’s a real nightmare to manage configuration files. In Silverlight projects like in web application, you can take advantage of Web Application Project Deployment features of Visual Studio 2010. In this blog, I’ll explain you :
In this post, I won’t explain SQL deployment.
In this post, I’ll explain how to use Web.config Transformation Syntax for Web Application Project Deployment. I’ll demonstrate this mechanism with two samples:
In your web.config file, you will define all parameters that you need in your application. For example, you need a DB connection string named MYDB. You need to define the connectionString add element with a specific name but without any connectionString value. You can also define, for example, compilation target to framework 4.0, debug mode. Finally, you disable custom errors.
This Web.Config file will be used/transformed to be compliant with the desired configuration.
Web.Debug.config
In the Web.Debug.Config file, you’ll create some transformation with a specific syntax. In this example, I’ll just add a specific connectionString dedicated to debug environment. In the Add element, you just need to add xdt:Transform and wdt:Locator=”Match(name)”. Those two attributes will inform that the transformation will be applied on an “add” xml element where the attribute name=”MyDB”, connectionString attribute will contains the specific connection string.
Here is the result of the translation after compiling and publishing the application.
You could also make some replacement or element removal and of course another DB connectionString replacement:
This mechanism is very helpfull, hoping that this helps.
ASP.NET Web Application Project Deployment Overview http://msdn.microsoft.com/en-us/library/dd394698(VS.100).aspx
Web.config Transformation Syntax for Web Application Project Deployment http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
Web Deployment: Web.Config Transformation http://blogs.msdn.com/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx