NAnt簡單介紹和我第一個例子

來源:互聯網
上載者:User

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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.