First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

A quite common task during the build process of an application is to change the configuration file with settings specific to test in on the testing environment or to release the product to customers.

NAnt has task that allow this: it can change the value of any attribute inside any XML file. You just need to be fluent with XPath in order to get the correct value to change.

<xmlpoke file="${testing.dir}\web.config"
     xpath="/configuration/appSettings/add[@key = 'ServerId']/@value"
     value="CODECLIMBER">
</xmlpoke>

This snippet include some example values: just change ServerId to setting key you want to change and CODECLIMBER to your setting's value.

And since the xmlpoke task can access anything with XPath, here is another example: change the tcp port for a remoting server:

<xmlpoke file="${MailPrimer.controlpanel.dir.testing}\web.config"
    xpath="/configuration/system.runtime.remoting/
        application/channels/channel[@ref = 'tcp']/@port"
    value="7666">
</xmlpoke>

This solution can be improved reading new setting's values from an external XML file (using the xmlpeek task) instead of hardcoding them inside the build script, but the core of the solution is the xmlpoke NAnt task.

posted on Wednesday, February 21, 2007 12:38 PM
Comments have been closed on this topic.