18 people following this project (follow)

Home What's New Properties Command Line Managing Properties MSI Integration Samples InstallUtil Roadmap

Project Description

XmlPreprocess is a command line tool that can modify specially annotated XML files much like a code preprocessor. It is useful for deploying XML configuration files to many environments. This new Codeplex project replaces the prior SourceForge xmlpreprocess project.
XmlPreprocessConceptual.gif

Goals

  1. Not have to maintain multiple configuration files or templates of configuration files for different environments. In other words, to have a single source of truth.
  2. Keep the original source of truth configuration file fully operational for development. Developers should be able to get the file directly from source control and run without having to make changes to it.
This is accomplished by decorating the configuration files with non-breaking comments that contain instructions for the preprocessor.

Examples

For example if you want to turn debug page compilation off when in production, you might do something like this:

<configuration>
  <system.web>
    <!-- #ifdef production -->
    <!-- <compilation defaultLanguage="c#" debug="false"/> -->
    <!-- #else -->
    <compilation defaultLanguage="c#" debug="true"/>
    <!-- #endif -->
  </system.web>
</configuration>
The debug setting will remain true for an unprocessed file, but when this file is deployed using the XmlPreprocess tool with the "production" property defined, the ifdef condition will be tested, and if true, the comments around its body content will be removed, and the else branch will be omitted entirely. This will render the following:

<configuration>
  <system.web>
    <compilation defaultLanguage="c#" debug="false"/>
  </system.web>
</configuration>
Another powerful way to use the preprocessor is to substitute properties into placeholders in your XML file much like in Ant or NAnt. Properties can be defined in an external XML file or passed on the command line to XmlPreprocess.exe.

For example if you have an application setting that contains the name of a remote server, but the name of that server changes from environment to environment, you may want to mark-up your XML like this:

<configuration>
  <appSettings>
    <!-- #ifdef _xml_preprocess -->
    <!-- <add key="server" value="${remoteserver}"/> -->
    <!-- #else -->
    <add key="server" value="developmentserver1"/>
    <!-- #endif -->
  </appSettings>
</configuration>
Then you can provide the value for the "remoteserver" property at deployment time via the Command Line or external settings file. For more information see Properties.

Additional Code Contributions

Special Thanks to Chris Sells and Tom Abraham for their contributions
  • Command Line Parser Code - Copyright 2002-2007 The Genghis Group (http://www.genghisgroup.com/) used with permission
  • Spreadsheet Import Code - Copyright 2007-08 Thomas F. Abraham used with permission

Last edited Jul 8 2009 at 4:35 PM by lorenh, version 16