in

ASP.NET Weblogs

Loren Halvorson's Blog

If your only tool is a hammer...

XmlPreprocess released

I finally waded through the process of setting up a sourceforge project and uploading content.

This is a simple command line utility that can be used to deploy config files to multiple environments without having to maintain multiple copies. It can be used as a custom action in your MSI to transform the files as they are being deployed to different environments.

http://xmlpreprocess.sourceforge.net/

The following is just pasted in from the overview topic of the users guide to give you an idea of what the tool does.

Overview

This tool can be used to preprocess an XML file and deploy it to a target environment making appropriate environment specific substitutions.

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 commandline or external settings file. For more information see properties.

Comments

 

TrackBack said:

December 15, 2004 4:59 AM
 

TrackBack said:

December 15, 2004 5:01 AM
 

TrackBack said:

December 16, 2004 6:08 AM
 

TrackBack said:

That guy Loren Halvorson has relased XmlPreprocess tool for preprocessing XML files, e.g. config files in .NET. It allows to perform the following tricks: &lt;configuration> &lt;system.web> &lt;!-- ifdef ${production} --> &lt;!-- &lt;compilation defaultLanguage="c#" debug="false"/> --> &lt;!-- else --> &lt;compilation defaultLanguage="c#" debug="true"/> &lt;!-- endif --> &lt;/system.web> &lt;/configuration> As you can see...
December 16, 2004 7:39 AM
 

TrackBack said:

December 16, 2004 8:54 AM
 

TrackBack said:

December 20, 2004 4:58 AM
 

TrackBack said:

December 20, 2004 5:34 AM
 

TrackBack said:

January 2, 2005 4:44 PM
 

TrackBack said:

Saw this over on Loren Halvorson’s blog.&nbsp; How timely, too.&nbsp; Deployed to a test server yesterday, and then everyone is yelling and screaming that this or that doesn’t work.&nbsp; Well, it all stemmed form the fact of how we were...
January 2, 2005 11:06 PM
 

Heinx said:

I use this to generate ant build files.ggrrreat

August 25, 2006 1:32 PM

Leave a Comment

(required)  
(optional)
(required)  
Add