Steve Hebert's Development Blog

.Steve's .Blog

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


Navigation

Blogs I Follow

Favorite Tools

Development Articles

Subscriptions

Post Categories

Article Categories



Monday, November 08, 2004 - Posts

NAnt-ing my database build

I finished the process of performing my database build using NAnt (actually NAntContrib).  I dusted off an old class library I used with a .Net plug-in I built for automating the database build and modified it so it could handle the NAnt.Core.Project object for floating messages, warnings and errors. 

Our database project under VS contains all of our stored procs, functions and trigger scripts (among others). Each script is responsible for testing if the contained object currently exists and takes appropriate steps.  Because the processing is order-critical, I've created an XML file format that enforces creation order and also allows for individual files or entire projects to be processed using a given line. 

I could have gotten this to run using only my class library instead of NAntContrib's SourceSafe additions (for grabbing the BuildScript), but I'll need some of NAntContribs functionality beyond the database build.  My NAnt script does the following:

(1) Get the database XML build script out of sourcesafe and store it to a working directory.  This XML build script signifies processing order and supports both individual files and directories. 
(2) Loads the XML build script in an XMLDocument object.
(3) Creates a StreamWriter object with the appropriate destination file name.
(4) Passes the objects to my class library to combine all the database scripts together into one file.
(5) NAnt then moves the file to the build area on the server

Here is the NAnt script I'm using to complete the task. I purposely pass the XMLDocument object because I'll eventually create different database build configurations using XSLT to automate the collection of these scripts.  I like the way this has turned out. 

<script language="C#" mainclass="Transform">
<references>
<include name="hssScriptBuilder.dll" />
</references>
<imports>
   <import name="System.Xml" />
   <import name="System.Xml.XPath" />
   <import name="System.Xml.Xsl" />
</imports>

<code>
<![CDATA[

//using System.Xml;

class Transform
{
   public static void ScriptMain(Project project)
   {
      // load the BuildConfig file gathered previously from sourcesafe      
      XmlDocument xDoc = new XmlDocument();
      xDoc.Load("./dbbuild/solution/BuildConfig.xml");

      // create the file for the entire script
      StreamWriter sw = new StreamWriter("./dbbuild/full_database_upgrade_script.sql");
      
      // hand the parameters to the class library to gather file contents
      hssScriptBuilder.hssSourceControl scc = new hssScriptBuilder.hssSourceControl();
      scc.ProcessSourceProject( xDoc, sw, "./dbbuild/workarea", project);
   }

}

]]>
</code>
</script>

posted Monday, November 08, 2004 2:26 PM by sdhebert




Powered by Dot Net Junkies, by Telligent Systems