Your SlideShare is downloading. ×
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply



Published on

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Ant, MSBuild, Shell Scripts
    8 March 2010
  • 2. What Is Ant?
    A build tool like make
    Open source
    from the Apache Jakarta project
    Implemented in Java
    Used to build many open source products
  • 3. Why Use Ant?
    Develop big programs by automating all tasks of compiling code, running tests, packaging and etc.
    Ant is more portable
    Ant only requires a Java VM
    Ant targets are described in XML
    Does not have cryptic syntax.
  • 4. How Does Ant Work?
    Ant commands (or tasks) are implemented by Java classes
    many are built-in
    others come in optional JAR files
    custom tasks can be created
    Each project using Ant will have a build file
    typically called build.xml since Ant looks for this by default
    Each build file is composed of targets
    these correspond to common activities like compiling and running code
    Each target is composed of tasks
    executed in sequence when the target is executed
    Ant targets can have dependencies
    for example, modified source files must be compiled
    before the application can be run
  • 5. How Does Ant Work? (Cont’d)
    Targets to be executed
    can be specified on the command line when invoking Ant
    if none are specified then the default target is executed
    execution stops if an error is encountered so all requested targets may not be executed
    Each target is only executed once
    for example
    the “test” and “deploy” targets both depend on “compile”
    the “all” target depends on “test” and “deploy”
    but “compile” is only executed once when “all” is executed
    Some tasks are only executed when they need to be
    for example, files that have not changed since the last time they were compiled are not recompiled
  • 6. <?xml version="1.0" ?>
    <project name="testAnt" default="run" >
    <property name="src" location="src/test" />
    <property name="output" location="build/classes" />
    <property name="msg" value="First Ant Making Directories..." />
    <target name="init">
    <echo> ${msg} </echo>
    <mkdir dir="${output}" />
    <target name="compile" depends="init">
    <echo> Compiling... </echo>
    <javac srcdir="${src}" destdir="${output}"/>
    Sample Build File (build.xml)
    Default target name
    Property values
    A target named by “init”
    Tasks which is executed in the sequence order
    Using property value “output”
  • 7. Sample Build File (Cont’d)
    <target name="run" depends="init,compile" >
    <java fork="true" classname="test.Main">
    <pathelement location="${output}"/>
    <target name="clean">
    <delete dir="${output}" />
    Means that the init,compile targets must be executed before this target
  • 8. MSBuild
    Microsoft Build Engine 
  • 9. What Is MSbuild?
    A Build tool like Ant
    Ships with Microsoft.NET Framework
    General purpose build automation system
    Uses XML-based language
    Syntax similar to Ant
  • 10. The Basic Elements
    Root container for Msbuild file (.csproj)
    <Project DefaultTargets="SampleTarget" xmlns="">
    A property defines a value associated with a name
    Using properties
    <Target Name="CreateDirectories“>
    <MakeDir Directories="$(MSBuildProjectDirectory)$(OutputDirectory)"/>
    All other elements
    property value
  • 11. The Basic Elements (cont’d)
    An item is a named reference to a file or to many files.
    Contain associated metadata, such as the full path or filename.
    <Compile Include="Program.cs" />
    <Compile Include=“Form.cs" />
    Using Items
    Reference the item collection in the example above with @(Compile)
    Accessing well known meta data of items
    syntax %(ItemMetadataName)
    Item collection named as Compile
  • 12. The Basic Elements (cont’d)
    Is a container for related tasks that will be executed sequentially
    Equivalent to Methods
    Must have a name
    <Target Name="SampleTarget" DependsOnTargets="DepTarget">
    <Message Text="SampleTarget executed" />
    <Target Name=“DepTarget">
    <Message Text="DependentTarget executed " />
    Means that the DepTarget must be executed before this target
  • 13. The Basic Elements (cont’d)
    Equivalent to a Statement
    Smallest unit of execution
    Must be declared within a Target
    Many standard ones included in MSBuild
    MakeDir,Copy, Message, Csc, Exec, etc.
    Custom tasks can be created
    <Project xmlns=“”>
    <Target Name="CreateDirectories">
    <MakeDir Directories=“output"/>
    Simple task which create directory called “output”
  • 14. Shell Scripts
    Windows scripting 
  • 15. About Shell Scripts
    Also called batch programs or scripts
    Contains one or more commands and has a .bat or .cmd file name extension
    for, goto, call and if, enable you to do conditional processing of the commands
    Commands are not case sensitive
    Executed by the command interpreter
  • 16. Batch Parameters
    Similar to Command line arguments
    Using Batch Parameters
    Using modifiers with batch parameters
    echo %~f0
    How to change the position of batch parameter?
    Using SHIFT /N command
    SHIFT /2
    would shift %3 to %2 and so on, and leave %0 and %1 unaffected.
    %* Reference to all the arguments, not including %0
    Expands %0 to a fully qualified path name.
  • 17. More Information About Commands