17
NAnt Nguyễn Văn Khiết

NAnt

  • Upload
    jag

  • View
    37

  • Download
    0

Embed Size (px)

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

Page 1: NAnt

NAnt

Nguyễn Văn Khiết

Page 2: NAnt

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

Page 3: 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.

Page 4: NAnt

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

Page 5: 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

Page 6: NAnt

Cấu trúc file build

• Project– name– default– basedir

Page 7: NAnt

Cấu trúc file build

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

Page 8: NAnt

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"/>

Page 9: NAnt

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>

Page 10: NAnt

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

Page 11: NAnt

Ví dụ

• nant

• nant init

• nant build

• nant clean

• nant init build

Page 12: NAnt

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>

Page 13: NAnt

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

Page 14: NAnt

Các hàm của NAnt

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

Page 15: NAnt

Các task của NAnt

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

Page 16: NAnt

Các task của NAnt

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

Page 17: NAnt

Các ví dụ của NAnt

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