Install prepare environment for Ant and create build script.


 

Follow the steps below to prepare environment for Ant and to write simple Ant build script to build a solution :

1. Download java from the link http://java.com/en/download/index.jsp

after download install Java.

2. set the JAVA_HOME variable in environment variable.

Go to Mycomputer–>properties–>Advanced–>Click Environment Variables button–>Click New button(in the system variables section)–>

set Variable name=JAVA_HOME

Variable value=c:\program Files\java\jre6(This is the path where java is installed it may vary)–> click ok button–>By clicking ok of all the window finish it.

Set JAVA_HOME variable

3. Download ant from http://ant.apache.org/bindownload.cgi

4. Unzip the download zip file(nothing to install for ant).

5.  Now set the ANT_HOME variable in environment variable.

Go to My Computer——>properties–>Advanced——->Click Environment Variables button——->Click New button(in the system variables section)—–>set Variable name=ANT_HOME

Variable value=C:\apache-ant-1.8.3-bin\apache-ant-1.8.3(The folder path where ant is unzipped)——> click ok button—–>By clicking ok of all the window finish it.

set the ANT_HOME variable in environment variable

6. Now set the ant path.

Go to Mycomputer–>properties–>Advanced–>Click Environment Variables button–>From System variables section select Path —–> click edit button——>in the last of the text box put the bin folder of the ant(from the unzipped location)precedding with semicolon like : ‘;C:\apache-ant-1.8.3-bin\apache-ant-1.8.3\bin’

Set ant Path

7. Open command prompt and type ant it will show error message ‘build.xml does not exist’. That means environment for ant is
prepared and now its time to prepare the build script with ant.

8. Here is a simple minimal ant script to build a project. Save the build script file as build.xml

<!--The project and the default task(target) that ant will execute if no target(task) is defined-->
<project name="MCSManagement" default="compile">
  
   <!--This task(target) initializes all the project variables-->
    <target name="init">
    
        <!-- Load environment variables -->
        <property environment="env" />
        
        <!-- Define the source repository -->
    <property name="src.dir"           location="C:\Developments\MCSManagement" />
    
    <!--Path of the msbuild which will be used as compiler -->
    <property name="msbuild"        location="${env.windir}/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe" />
    
    <!--Full path of the solution file that have to compile-->
    <property name="sln.file"       location="${src.dir}/MCSManagement.sln" />
    
  </target>
  
  <!--This target(task) compiles the project and initializes all the needed variables.This target(task) is dependent on the init target-->
  <target name="compile" depends="init">
    <!--Directory is the directory where the solution file is located-->
    <exec dir="${src.dir}" executable="${msbuild}" failonerror="true">
      <!--The path of the solution file-->
      <arg line="${sln.file}"/>
    </exec>
  </target>
  
</project>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

9. Now start the command prompt, use cd to enter the location where the build.xml is located. Now to build the solution enter the command "ant compile"

ant command