[#VS2013] HowTo: Generate different app.config for debug or release in non-web projects

image

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

image

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”.

image

This action will add 2 dependent files of the App.Config, for each type of configuration.

image

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

References: http://blogs.msdn.com/b/webdev/archive/2012/08/20/profile-specific-web-config-transforms-and-transform-preview.aspx

Greetings @ Home

El Bruno

imageimageimageGoogle

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s