Sandeep wrote:







I need to deploy my application to various environments
using a central build server. I have created sample xml that list the 
files/folders
to be copied in each environment.



I want to call this XML file though NAnt and use Nant script
to run copy task based on the folders specific in xml. I am using server
aliases which are also defined in the same xml.




Has anyone tried this approach before…what is the best
scripting approach for this type of requirement? I am

If I'm understanding you correctly, you expect the xml file to be maintained by hand. I think that using XML for this purpose is making it much too complicated. NAnt simply doesn't have a rich enough set of XML functions, and if you're going to
drop into C#, you may as well do it all in C# and skip the
NAnt, or else just have the C# generate a NAnt script.


But it's possible to do this in pure NAnt by using the features of the <foreach> task. Here's what I suggest you do:

1. Create a directory for environment description files. Create one file per environment Each file will be a NAnt project that defines the properties for that environment, e.g.

 <project name="environment.dev" >
   <property name="AppServer" value="abcdev" />
   <property name="WebServer" value="xyzdev" />
 </project>

So far, so good.

2. Create a file that contains the mappings between source and destination files, and the machine, one per line, with a well-chosen separator. For example:

 WindowsApp\AbcService\bin\release:AbcService\AppServer
 WebApp\AbcWeb:Inetpub\AbcWeb:WebServer

3.  Loop over the environment files :

 <foreach item="File" property="environment.file">
   <in>
     <items>
       <include name="environments/*.environment" />
     </item>
   </in>
   <do>
     <call target="process-environment" />
   </do>
 </foreach>

4.  The process-environment target deals with exactly one environment file:

 <target name="process-environment">
   <include buildfile="${environment.file}" />
   <call target="do-copy" />
 </target>

5.  The do-copy target loops over the mapping file created in step 2:

 <target name="do-copy">
   <foreach item="Line" in="copy.commands" delim=":" 
property="source,dest,server">
     <do>
       <copy file="${source}" tofile="\\${server}\${dest}" />
     </do>
   </foreach>
 </target>

Gary




------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20 _______________________________________________ Nant-users mailing list Nant-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to