NAnt

Preview:

DESCRIPTION

NAnt. Nguyễn Văn Khiết. Nội dung. Giới thiệu Cấu trúc build.xml Các kiểu dữ liệu trong NAnt Thực thi chương trình từ NAnt. Giới thiệu. http://nant .sourceforge.net NAnt là một công cụ hỗ trợ build ứng dụng .NET. File build dưới định dạng XML - PowerPoint PPT Presentation

Citation preview

NAnt

Nguyễn Văn Khiết

Nội dung

• Giới thiệu

• Cấu trúc build.xml

• Các kiểu dữ liệu trong NAnt

• Thực thi chương trình từ NAnt

Giới thiệu

• http://nant.sourceforge.net

• NAnt là một công cụ hỗ trợ build ứng dụng .NET.

• File build dưới định dạng XML

• Tổ chức dưới dạng cây trong đó các target sẽ được gọi thực thi.

Cài đặt NAnt

• Giải nén Nant vào một thư mục

• Thay đổi biến môi trường Path chỉ tới thư mục bin của thư mục cài Nant

Cấu trúc file build

• Tập tin cấu hình cách thức biên dịch, thực thi và triển khai project

• Mỗi buildfile chứa– 1 project– Nhiều target

• task– id attribute

Cấu trúc file build

• Project– name– default– basedir

Cấu trúc file build

• Các thuộc tính của target– name– depends– if– unless– description

Cấu trúc file build

• Target- Phụ thuộc giữa các target

<target name="A"/>

<target name="B" depends="A"/>

<target name="C" depends="B"/>

<target name="D" depends="C,B,A"/>

Ví dụ file build<?xml version="1.0"?>

<project name="Hello World" default="build" basedir=".">

<description>The Hello World of build files.</description>

<target name="clean" description="remove all generated files">

<delete file="HelloWorld.exe" failonerror="false" />

<delete file="HelloWorld.pdb" failonerror="false" />

</target>

<target name="build" description="compiles the source code">

<csc target="exe" output="HelloWorld.exe" debug=“true">

<sources>

<includes name="HelloWorld.cs" />

</sources>

</csc>

</target>

</project>

Thực thi NAnt

• Thực thi một file build:– Nant –buildfile:xxx

• Tìm và thực thi file .build trong thư mục hiện hành– Nant

• Thực thi target clean trong file .build ở thư mục hiện hành– Nant clean

Ví dụ

• nant

• nant init

• nant build

• nant clean

• nant init build

Tham số trong file build<?xml version="1.0"?>

<project name="Hello World" default="build" basedir=".">

<description>The Hello World of build files.</description>

<property name="debug" value="true" overwrite="false" />

<target name="clean" description="remove all generated files">

<delete file="HelloWorld.exe" failonerror="false" />

<delete file="HelloWorld.pdb" failonerror="false" />

</target>

<target name="build" description="compiles the source code">

<csc target="exe" output="HelloWorld.exe" debug="${debug}">

<sources>

<includes name="HelloWorld.cs" />

</sources>

</csc>

</target>

</project>

Truyền tham số khi gọi NAnt

• Sử dụng tham số trong file buildnant

• Sử dụng tham số dòng lệnh (chỉ có ý nghĩa khi overwrite = “true”)

nant -D:debug=false

Các hàm của NAnt

• (Xem phần Function Reference trong document của Nant)

Các task của NAnt

• cl• copy• csc• cvs• delete• echo• if• ilasm

Các task của NAnt

• incluse• jsc• lib• mail• mkdir• move• regex• …• (Xem thêm Task Reference trong Nant document)

Các ví dụ của NAnt

• Xem phần example trong thư mục cài NAnt

Recommended