I’ve blogged a before for web.config transformations and how I would like to see them in other projects. While for Windows Azure cloud service project there is already similar feature implemented, I wonder why there is no out of the box support for other project types.
Here I will reveal the powerful, yet simple implementation of such transformation over your ServiceReferences.ClientConfig files. Thus you will no longer wonder what are your service endpoints, and which endpoint you are using. And this is not Windows Azure specific. It is relevant for any Silverlight project.
Just implement these simple steps:
1. Edit your .csproj file of the Silverlight application. Add the following block:
<!-- Generate transformed app config in the intermediate directory –>
<!-- Force build process to use the transformed configuration file from now on. –>
2. Add new XML file to your project. Name it ServiceReferences.[BuildConfiguration].ClientConfig. Where [BuildConfiguration] can be the name of *any* build configurations you have defined for your project. The default build configurations are “Debug” and “Release”, but you may add as many as you like, to suit your development/testing/staging/live environments. Remember to set “Build Action” to “None”, and “Copy to output directory” to “Never”:
3. Add the required content in that custom file. For example, if you want to just change an endpoint for a service, you will have something like this (ServiceReferences.Debug.ClientConfig):
<?xml version="1.0" encoding="utf-8"?>
For more information on XML transformations supported, please take a look at the MSDN documentation for Web.Config transformations. Do not panic! The documentation is for “web.config” transformations, but these are just XML transformations that can transform any XML file