NAnt是.NET平台的工具,类似于C语言编译工具make,不过又不仅仅是make的功能,它可以下载源码,重建数据库,编译程序,运行测试,发送邮件(报告测试结果)因此它是持续集成环境里重要的工具。使用:nant首先一个命令行程序,他和make一样解析makefile类似,他解析*.build文件,不同的是build文件是一个XML格式的脚本,并且XML节点和属性有完善仔细的定义,这个可以看它的doc文档(跟随软件一起下载下来了)例如<csc />就是告诉nant执行编译命令,下面是我第一个例子,虽然还是不完善,但是是我一个阶段性成果
default.build
<?xml version="1.0"?> <project name="WebApp" default="run_test" basedir="."> <!--编译方式--> <property name="DEBUG" value="true" /> <!--目录与文件配置--> <property name="SRC" value="./trunk" /> <property name="BIN" value="./trunk/bin" /> <property name="SQL_SCRIPT" value="./trunk/script/db.sql" /> <!--SVN 地址和帐号信息--> <property name="SVN_SERVER" value="http://127.0.0.1:8080/svn/WebApp/trunk" /> <property name="SVN_USERNAME" value="lishujun" /> <property name="SVN_PASSWORD" value="aaa" /> <!--数据库信息--> <property name="SQL_SERVER" value="(local)" /> <property name="SQL_USERNAME" value="sa" /> <property name="SQL_PASSWORD" value="123456" /> <!--删除源码和可执行程序--> <target name="clean"> <delete dir="${SRC}" /> </target> <!--重新获取源码,重建SQL数据库--> <target name="checkout" depends="clean"> <exec program="svn" commandline="export ${SVN_SERVER} --username ${SVN_USERNAME} --password ${SVN_PASSWORD}" /> <exec program="sqlcmd" commandline="-S ${SQL_SERVER} -U ${SQL_USERNAME} -P ${SQL_PASSWORD} -i ${SQL_SCRIPT}" /> </target> <!--编译程序--> <target name="build_dal" depends="checkout"> <csc target="library" output="${BIN}/DAL.dll" debug="${DEBUG}"> <sources basedir="${SRC}/DAL"> <include name="*.cs"/> </sources> </csc> </target> <target name="build_bll" depends="build_dal"> <csc target="library" output="${BIN}/BLL.dll" debug="${DEBUG}"> <sources basedir="${SRC}/BLL"> <include name="*.cs"/> </sources> <references basedir="${BIN}/"> <include name="DAL.dll" /> </references> </csc> </target> <target name="build" depends="build_bll"> <csc target="library" output="${BIN}/UnitTest.dll" debug="${DEBUG}"> <sources basedir="${SRC}/UnitTest"> <include name="*.cs"/> </sources> <references basedir="${BIN}/"> <include name="BLL.dll" /> <include name="${nant::scan-probing-paths('nunit.framework.dll')}" /> </references> </csc> </target> <!--运行测试--> <target name="run_test" depends="build"> <nunit2> <formatter type="Plain" /> <test> <assemblies basedir="${BIN}"> <include name="UnitTest.dll" /> </assemblies> <references basedir="Libraries"> <include name="BLL.dll" /> </references> </test> </nunit2> </target> </project>