Erick,
I found a little time to work on it, but it's still a
fairly intensive solution. I wrote a C# program that
modifies the config files based on environment. You
have to get creative with xpaths in order to use it,
but it does the job. I thought about using pattern
substitution, but too much chance for error... Here's
the program. Hope you find it useful. Let me know if
you have some ideas for improvement.
Thanks,
Eric
--- Erick Thompson <[EMAIL PROTECTED]> wrote:
> Eric,
>
> Did you ever get this problem worked out? I'm
> looking at a similar situation, and would love to
> have something I could reuse, as opposed to
> hardcoding app.config -> [ProjectName].exe.config.
>
> I'm using the solution task, without the project
> files specified. If I specify the project files, I
> could do an automatic copy, but the build in project
> detection code works quite well.
>
> Thanks,
> Erick
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> Behalf Of
> > Eric Fetzer
> > Sent: Thursday, November 13, 2003 10:29 AM
> > To: Nant Users
> > Subject: [Nant-users] app.config -->
> project.exe.config
> >
> >
> > Does NAnt have a way to handle the renaming and
> > deployment of project config files during the
> build
> > process? I've been hardcoding copies in a build
> file
> > I use for staging, but naturally, don't like this
> > solution. Thanks - Eric
> >
> > __________________________________
> > Do you Yahoo!?
> > Protect your identity with Yahoo! Mail
> AddressGuard
> > http://antispam.yahoo.com/whatsnewfree
> >
> >
> >
>
-------------------------------------------------------
> > This SF.Net email sponsored by: ApacheCon 2003,
> > 16-19 November in Las Vegas. Learn firsthand the
> latest
> > developments in Apache, PHP, Perl, XML, Java,
> MySQL,
> > WebDAV, and more! http://www.apachecon.com/
> > _______________________________________________
> > Nant-users mailing list
> > [EMAIL PROTECTED]
> >
>
https://lists.sourceforge.net/lists/listinfo/nant-users
> >
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
/*
Copyright (c) 2003, 2004 Eric Fetzer <[EMAIL PROTECTED]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Eric Fetzer nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------------
This program will open an xml master settings file that contains information to
set settings in all of the config files that are environmentally
dependant. The master file contains:
1) Where to get the config files to change
2) Where to save the changed version down to (staging area)
3) What settings need to be changed
4) The value those settings will be set to for each environment
This program will loop through the settings for each of these files, make
the necessary changes for the environmental settings (environment is passed
in as an argument), and save the config files down in the desired location.
*Example master config section:
<?xml version="1.0" encoding="utf-8" ?>
<configFile name="D:\myProject\myApp\app.config"
newLocation="D:\myProject\Deploy\DocTier\myApp.exe.config">
<setting
xpath="/configuration/appSettings/[EMAIL PROTECTED]'ConnectionString']/@value"
dev="server=server1;database=database1;Connection
Reset=false;Trusted_Connection=True;"
qa="server=server2;database=database2;Connection
Reset=false;Trusted_Connection=True;"
stage="server=server3;database=database3;Connection
Reset=false;Trusted_Connection=True;"
prod="server=server4;database=database4;Connection
Reset=false;Trusted_Connection=True;"
<setting
xpath="/configuration/appSettings/[EMAIL PROTECTED]'ErrorLogPath']/@value"
dev="D:\projects\myProgram\ErrorLogs"
qa="D:\Program Files\myProgram\ErrorLogs"
stage="D:\Program Files\myProgram\ErrorLogs"
prod="D:\Program Files\myProgram\ErrorLogs"
</configFile>
There will be one configFile section for each config file with system dependant
information.
*/
using System;
using System.IO;
using System.Xml;
public class CreateConfig
{
public static void Main(string[] args)
{
string env = args[0];
// Load up master config file
XmlDocument masterConfigDoc = new XmlDocument();
masterConfigDoc.Load(@"D:\projects\MasterConfig.xml");
// Get list of config files from master
XmlNodeList configFiles = masterConfigDoc.SelectNodes("configFile");
// Declare variables to be used in loop
string configFileName;
string newConfigLocation;
// Loop through config files contained in master
foreach (XmlElement configFile in configFiles)
{
// Open this config file
XmlDocument newConfig = new XmlDocument();
// Get the name of the config file we are modifying
configFileName = configFile.GetAttribute("name");
// Find the location to save the new config file to
newConfigLocation = configFile.GetAttribute("newLocation");
// Load that bad boy up into our new config file
newConfig.Load(configFileName);
// Get list of settings in this config file to be changed
XmlNodeList settings = configFile.SelectNodes("setting");
// Declare variables to be used in loop
string xpath;
string newValue;
// Loop through the settings and save settings in new
environments config file
foreach (XmlElement setting in settings)
{
// Get the xpath from the master config file to the
item to change
xpath = setting.GetAttribute("xpath");
// Get the environmental setting to set in the new
environments config file
newValue = setting.GetAttribute(env);
// Get to the node we are modifying in the new config
file
XmlNode targetNode = newConfig.SelectSingleNode(xpath);
// Set the value in the new config file
targetNode.Value = newValue;
}
// Save the target config file to new location
newConfig.Save(newConfigLocation);
}
}
}