Nant使用简介续

    技术2022-05-19  21

    若有如下代码目录结构:

    其中src下包含cs源文件,如dd.cs,class1下包含源文件,如aa.cs, bb.cs,class2下同样包含源文件,如cc.cs,共计4个cs文件。生成的dll文件将被放到release目录下,同时,还需要拷贝到一个公共的目录,比如//srv/release,可以编写如下nant文件来实现:

     

    <project name="mybuild" basedir="."> <!--define global variables--> <property name="debug" value="true" overwrite="false" /> <property name="output_dir" value="./release" /> <property name="src_dir" value="./src/" /> <property name="release_name" value="myapp.dll" /> <property name="pub_folder" value="//srv/release" /> <!--clean task: to delete the existing dll files--> <target name="clean" description="clean release dir..."> <!--two ways to delete files--> <delete file="${output_dir}/${release_name}"/> <delete> <fileset basedir="${output_dir}"> <include name="*.dll"/> <exclude name="*.config"/> </fileset> </delete> </target> <!--build task: to build the source codes and generate dll--> <target name="build" description="build the source codes..."> <csc target="library" output="${output_dir}/${release_name}" debug="${debug}"> <!--if referenced othere dlls, need to add them--> <references basedir="."> <include name="Microsoft.VisualBasic.dll" /> </references> <sources basedir="${src_dir}"> <!--two ways to add source code files--> <include name="dd.cs" /> <include name="**/*.cs" /> </sources> </csc> </target> <!--publish task: copy the generated library to shared server folder--> <target name="publish" description="copy the build to public folder..."> <!--copy all files from ./release to //srv/release--> <copy todir="${pub_folder}"> <fileset basedir="${output_dir}"> <include name="*.*"/> </fileset> </copy> </target> </project>

     

    该文件命名为mybuild.build,存放在workspace目录下。

     

    命令行切换到c:/workspace目录下,执行:

    nant -buildfile:mybuild.build build 可以看到如下输出:

     

    几个注意点:

    1. 目录的配置;

    2. 如果有手动引用的dll,一定要记得加在references项中,不能忘记了dll后缀名;

    3. csc结点中,output和target属性是必选项,其他的根据需要可选;

    4. 如果release目录里面已经有了生成的dll文件,需要先进行clean操作,否则不会有新build生成。

     

     

     

     

     


    最新回复(0)