Hello.
If you’ve ever worked with web projects, you’ve probably used a functionality that allows you to have a different configuration file in the application (web.config), for different build modes (by default are DEBUG or RELEASE). If you want to see a post explaining this operation, this one is great > MSDN.
Initially this functionality does not come “out of the box” for other types of projects. Although it is possible to implement the same pattern using the “Configuration Transform” AddIn for Visual Studio. Here is an example for a WPF project.
We start from a project that has a defined Setting and a unique App.Config
To add a specific settings for the DEBUG and RELEASE builds, we select the App.config, deploy the contextual menu and select “Add Config Transforms”.
This action will add 2 dependent files of the App.Config, for each type of configuration.
If we open the file release, we will see that it is empty. If for example we have the Setting “SomeSpecial” value to Release, we can add the following code:
1: <?xml version="1.0"?>
2: <!-- For more information on using app.config transformation
3: visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
4: <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
5: <applicationSettings>
6: <WpfApplication1.Properties.Settings>
7: <setting name="SomeSpecial" serializeAs="String"
8: xdt:Transform="Replace" xdt:Locator="Match(name)">
9: <value>Something for RELEASE</value>
10: </setting>
11: </WpfApplication1.Properties.Settings>
12: </applicationSettings>
13: </configuration>
The code of the above definition, described in line 7, the < setting > node to be replaced when you find a match with the “name” attribute. In this way this value will be replaced when a compilation generated in Release mode.
Using this feature, can we make sure not “deploy wrong values to release environments”, values that we use in DEBUG in our dev environment.
Download: http://visualstudiogallery.msdn.microsoft.com/579d3a78-3bdd-497c-bc21-aa6e6abbc859
Greetings @ Home
El Bruno