skip to the main content area of this page
Patterns and Practices

 

Automated Environmental Overrides Merging via Batch File or NAnt Build File


One of the many challenges of software development is the management and synchronization of application configuration files in the various application environments: Development, Test, Staging, Production, etc. The use of Enterprise Library and its extensive use of configuration information compounds this problem even more.

With Enterprise Library 3.0 this challenge is more manageable through the use of a new feature in the configuration tool called Environmental Overrides. Environmental Overrides allow one to override features in a default configuration file and merge those changes to create an environment specific configuration file. This merging can be done manually or during the build process.

For more information on Environmental Overrides, see Environmental Overrides in Enterprise Library 3.0.

Included with Enterprise Library 3.0 is a console application, called MergeConfiguration.exe, to automate the merging process during builds. The MergeConfiguration.exe file is located in the bin directory will the Enterprise Library assemblies.

Running MergeConfiguration.exe will display the following usage information:

Usage: MergeConfiguration.exe ConfigFile DeltaFile [MergedFile]

  • ConfigFile - The main configuration file (.config), which will be merged
  • DeltaFile  - The Environment Delta File (.dconfig) that contains the information that should be merged into the main configuration file.
  • The resulting file [MergedFile] - The output file this is generated after merging the ConfigFile and DeltaFile. If not specified, the filename stored in the DeltaFile is used.

 

Merging via Batch File

Assuming a default configuration file of App.config and a Production DeltaFile of Product.dconfig, one can create a Production.config file that is the result of a merging of the two as simple as:

[path]\MergeConfiguration.exe App.config Production.dconfig Production.config

where [path] is the path to the console application.

 

Merging via NAnt Build File

Again, assuming a default configuration file of App.config and a Production DeltaFile of Product.dconfig, one can create a Production.config file that is the result of a merging of the two as simple as creating a file called EO.build:

 

<?xml version="1.0" encoding="utf-8" ?>
<project name="EnvironmentalOverrides" default="generateconfig">

    <target name="generateconfig">
        <exec program="[path]\MergeConfiguration.exe">
                <arg value="App.config" />
                <arg value="Production.dconfig" />
                <arg value="Production.config" />
        </exec>
    </target>

</project>

 

and running nant.exe -buildfile:EO.build.

 

Conclusion

Environmental Overrides and the MergeConfiguration.exe console application are very helpful in managing and synchronizing application configuration files in the various application environments.


Tags: EntLibConfigurationEditor, EnvironmentalOverrides


Topics



 

Popular Tags



Recent Links