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>