DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

Generate DB script using NAnt's copy-replacetokens task

most of our .NET projects has a database project with three scripts in it, (1) create database script, (2) database shema script and the (3) default data script.  for our pre-release, we packaged the database creation with default data in our Installshield project so we made use of the SQLScripts section.  I needed to automate the generation of this script file containing the said three script files in our database project which will be used by the Installshield project, so the replacetokens feature of copy task sounds a perfect feature for this requirement.

i just have a script file with NAnt tokens in it like the one below:

@DROPCREATE@

USE HCSV2
GO

@SCHEMA@

USE HCSV2
GO

@DATA@

below is the NAnt task for the generation of the script file:

    <target name="generatescript">

        <loadfile file="${script.dir}\DropCreateHcsDatabase.sql" property="db.dropcreate"></loadfile>

        <loadfile file="${script.dir}\HcsDatabase.sql" property="db.schema"></loadfile>

        <loadfile file="${script.dir}\HcsData.sql" property="db.data"></loadfile>

        <copy todir="${dist.dir}">

            <fileset basedir="${script.dir}">

                <include name="HCSV2.sql" />

            </fileset>

            <filterchain>

                <replacetokens>

                    <token key="DROPCREATE" value="${db.dropcreate}" />

                    <token key="SCHEMA" value="${db.schema}" />

                    <token key="DATA" value="${db.data}" />

                </replacetokens>

            </filterchain>

        </copy>

    </target>

basically the @tokens@ are replaced with their corresponding script contents.  we also used the same feature so we don't have hardcoded file paths for the assemblies included in our installshield project.  that way, the build will compile regardless of the root folder where the project is located.


Posted 02-05-2007 8:03 PM by jokiz

Copyright DevPinoy 2005-2008