Here you go Brian:

---------------------------------------------------------------------------------

  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);
                }
        }
}


--- Brian Beaudet <[EMAIL PROTECTED]> wrote:
> Eric,
> 
> At this point I'm only using Nant to perform test
> builds and run unit
> tests at some regular frequency (nightly or
> continuously?).  This is all
> done on a dedicated server.  
> 
> Each developer is responsible for grabbing the
> source code and modifying
> the config files (custom or .config) to suit his
> development
> environment.  If we send anything to be QA tested or
> out for release we
> send out a setup program and we have scripts that
> run as part of the
> setup package that modify file paths.  Connection
> strings usually have
> to be manhandled to get them right, however.
> 
> I'm interested in what you've developed as maybe a
> way to help each
> particular person modify the config file as they
> seem fit.  Currently
> I'm using XMLNotepad for that just to make it easier
> to read then
> opening the XML file in Notepad.
> 
> If you'd post your code, I'll give it a look-see and
> see what I can do
> with it.
> 
> Thanks,
> 
> Brian
> 
> 
> > -----Original Message-----
> > From: Eric Fetzer [mailto:[EMAIL PROTECTED]
> > Sent: Friday, April 09, 2004 11:07 AM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [Nant-users] Config Files?
> > 
> > If there are no settings that would vary based on
> the
> > environment you deploy to, my program would be
> > completely useless to you.
> > 
> > 
> > --- Brian Beaudet <[EMAIL PROTECTED]>
> wrote:
> > > Eric,
> > >
> > > I've started using custom XML files for
> > > configuration purposes instead
> > > of the <appSettings> section in the normal
> .config
> > > files.  How would
> > > your program be useful in that scenario?
> > >
> > > The only things I leave in the App.config file
> (or
> > > Web.config) would be
> > > configuration settings for log4net or some other
> > > third party tool.
> > >
> > > Thanks,
> > > Brian
> > >
> > > > -----Original Message-----
> > > > From: Eric Fetzer
> [mailto:[EMAIL PROTECTED]
> > > > Sent: Thursday, April 08, 2004 5:14 PM
> > > > To: [EMAIL PROTECTED]; Nant Users
> > > > Subject: Re: [Nant-users] Config Files?
> > > >
> > > > I deploy to several different environments
> with
> > > > settings in my app.config as well as
> web.config
> > > files
> > > > that vary (such as paths to a file share or
> > > database
> > > > connection string).  So I wrote a C# program
> that
> > > > based on an XPath (mapping in the xml file),
> > > > substitutes the appropriate value.  I call
> this
> > > from
> > > > the build file for each of the systems I will
> > > deploy
> > > > to and create an NSIS installation file for
> each
> > > (with
> > > > appropriate config(S) contained therein). 
> I've
> > > posted
> > > > this program before.  If you want it, I can
> post
> > > > again.  It's commented pretty well as to how
> to
> > > use
> > > > it.
> > > >
> > > > Eric
> > > >
> > > >
> > > > --- Brian Beaudet <[EMAIL PROTECTED]>
> > > wrote:
> > > > > I hate to think I'm posting the same old
> > > questions
> > > > > but I've searched and
> > > > > haven't found much out there on this topic.
> > > What do
> > > > > others do to create
> > > > > a programname.exe.config file from their
> > > App.config.
> > > > >  Is it as simple as
> > > > > a <copy> task?  That's what I'm doing now. 
> I
> > > don't
> > > > > keep much in the
> > > > > App.config file but my application still
> whines
> > > if
> > > > > it's not there.
> > > > >
> > > > >
> > > > >
> > > > > Brian M. Beaudet
> > > > >
> > > > > Director, Research & Development
> > > > >
> > > > > EfficiencyLab, LLC
> > > > >
> > > > > www.efficiencylab.com
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Yahoo! Small Business $15K Web Design Giveaway
> > > > http://promotions.yahoo.com/design_giveaway/
> > >
> > 
> > 
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Small Business $15K Web Design Giveaway
> > http://promotions.yahoo.com/design_giveaway/
> 
> 
> 
>
-------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux
> Tutorials
> Free Linux tutorial presented by Daniel Robbins,
> President and CEO of
> GenToo technologies. Learn everything from
> fundamentals to system
>
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Nant-users mailing list
> [EMAIL PROTECTED]
>
https://lists.sourceforge.net/lists/listinfo/nant-users


__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to