DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Competing Consumers With Spring Boot and Hazelcast
  • MLOps: Definition, Importance, and Implementation
  • Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Competing Consumers With Spring Boot and Hazelcast
  • MLOps: Definition, Importance, and Implementation
  • Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs

Automating Your Computer Tasks with NAnt

Boyan Kostadinov user avatar by
Boyan Kostadinov
·
Jan. 30, 08 · News
Like (0)
Save
Tweet
Share
9.15K Views

Join the DZone community and get the full member experience.

Join For Free
As part of working on a installer for .NET web application, I decided to use NAnt (stands for Not Ant) which is a .NET equivalent of the popular Java based ANT automation tool. If you don't know what an automation tool is, check out the Build Tool article on Wikipedia. The beauty of NAnt is in the fact that you can automate many tasks and once you have a working "build" file, you do not have to worry about it again. Here is some of you can do with the help of NAnt:
  • Install and register ASP.NET with IIS without user intervention
  • Start/stop/pause or install windows services
  • Zip or unzip files
  • Changes values inside text or xml files
  • Create files and/or directories
  • Copy/move files and/or directories
  • Set directory and/or file security permissions
  • Much more
  • If that is not enough, you can always extend NAnt with your own custom tasks (written in VB.NET or C#)
That being said, here are the steps to get started with NAnt:
  1. Get NAnt from http://prdownloads.sourceforge.net/nant/nant-0.85-bin.zip?download
  2. Get NAntContrib from http://prdownloads.sourceforge.net/nantcontrib/nantcontrib-0.85-bin.zip?download
  3. Extract NAnt in “C:\Program Files\NAnt”
  4. Extract NAntContrib\bin in “C:\Program Files\NAnt\bin”
  5. Create a NAnt.bat file in C:\Windows with the following:
    @echo off
    “C:\Program Files\NAnt\bin\nant.exe” %*
  6. Create and run a sample build file. Build files can perform many functions, from compiling your .NET application to downloading files from the net. For a list of Tasks, see the NAnt Tasks list and the NAntContrib Tasks list.
Below is a sample build file that takes a currently installed web application, pre-compilies it and creates a zip file of the pre-compiled application ready to be deployed:

<project name="test" default="deploy" basedir="." xmlns="http://nant.sf.net/schemas/nant.xsd">
<description>Precompiles and zips a test project</description>
<property name="debug" value="true" overwrite="true" />

<!-- The target directory where the application will be deployed and the zip file created -->
<property name="targetDirectory" value="." overwrite="false" />

<!-- The temporary directory where the web application will be precompiled -->
<property name="deployTarget" value="${path::combine(path::get-full-path(targetDirectory), 'deploy')}" overwrite="true" />

<!-- The virtual directory that the web application resides in -->
<property name="virtualDirectory" value="webApplication" overwrite="true" />

<!-- The name of the zip file to create when zipping the deployed web application -->
<property name="deployZipFilename" value="webApplication.zip" overwrite="true" />

<!-- The location where the zip file will be created -->
<property name="deployZipFileLocation" value="${path::combine(path::get-full-path(targetDirectory), deployZipFilename)}" overwrite="true" />

<!-- The location of the .NET Framework directory (for version 2) -->
<property name="dotnetLocation" value="${framework::get-framework-directory('net-2.0')}" overwrite="true" />

<!-- 'clean' target deletes the previously created zip file and deploy directory -->
<target name="clean" description="Remove all generated files">
<!-- Delete the existing zip file -->
<delete file="${deployZipFileLocation}" if="${file::exists(deployZipFileLocation)}" />

<!-- Delete the existing deploy directory -->
<delete dir="${deployTarget}" if="${directory::exists(deployTarget)}" />
</target>

<!-- 'build' target precompiles this ASP.Net application into the deployTarget directory -->
<target name="deploy" description="Precompiles the web application and creates a zip file for it" depends="clean">
<!-- Precompile the web application with the built-in .NET utility -->
<exec
basedir="."
program="${dotnetLocation}\aspnet_compiler.exe"
commandline="-nologo -fixednames -v ${virtualDirectory} "${deployTarget}""
workingdir="."
failonerror="true" />

<!-- Clean up the "deployTarget" directory -->
<delete>
<fileset>
<!-- Delete any visual studio related files -->
<include name="${deployTarget}/*.TempSolution" />
<include name="${deployTarget}/**/*.scc" />
<include name="${deployTarget}/**/*.resx" />
<include name="${deployTarget}/**/*.txt" />
<include name="${deployTarget}/**/*.db" />
<include name="${deployTarget}/**/*.vssscc" />

<!-- Delete all the files in the upload and files directory -->
<include name="${deployTarget}/upload/**/*" />
<include name="${deployTarget}/files/**/*" />
</fileset>
</delete>

<!-- Create a zip file from precompiled web application -->
<zip zipfile="${deployZipFileLocation}" includeemptydirs="true">
<fileset basedir="${deployTarget}">
<include name="**/*" />
</fileset>
</zip>

<!-- delete the deployTarget directory -->
<delete dir="${deployTarget}" />
</target>
</project>
NAnt Task (computing) Computer

Opinions expressed by DZone contributors are their own.

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Competing Consumers With Spring Boot and Hazelcast
  • MLOps: Definition, Importance, and Implementation
  • Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: