MergeConfig

Maintaining .net configurations across development, test and production regions have always been a problem that is faced. To ease this process,  I was thinking of creating a utility that makes it easy to use and help deployments. The goal was to eliminate need to save and maintain multiple files for various regions. Here it is, “MergeConfig”

The utility uses ‘MergeConfig.xml’ as XML file to hold this information. The structure of this XML file is organized as:

  • Deployment Region <deploymentRegion>
  • File Info <fileInfo>
  • Maintain Configuration <maintainConfig>

The Deployment Region specifies the name of the region, i.e. dev, test, prod.This section is to be defined one per region.

<deploymentRegion name="Development">

The File Info section specifies the file path that is to be merged. This section is defined one per region per file

<fileInfo fileName="D:\Project\App.config">

The Maintain Configuration section specifies what attribute to be replaced with what.

<maintainConfig findXPath="//root/configuration/add[@key='TestConfig']" replaceAttribute="value" replaceWith="ABC" />

Here the ‘findXPath’ attribute defines which element to look for in the configuration file. ‘replaceAttribute’ defines which attribute in the element has to replaced and ‘replaceWith’ defines the new value for that region. For example, consider the following in the App.config file

<root>
	<connections>
		<connection ID="main" connectionString="DataSource=DEV;Password=PWD;UID=UID" />
		<connection ID="log" connectionString="DataSource=DEV;Password=PWD;UID=UID" />
	</connections>
</root>

We would need to use,

<maintainConfig findXPath="//root/connections/connection[@ID='main']" replaceAttribute="connectionString" replaceWith="Data Source=localhost" />

The syntax for running this command line utility is:

MergeConfig.exe {/r | /region}: {/v | /verbose}

The switch /r specifies which region to use, and /v specifies if verbose output is required.
Examples:

MergeConfig.exe /r:Development /v
MergeConfig.exe /r:Development /verbose
MergeConfig.exe /region:Development

Click Download to get the compiled utility.

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