Automating Your Computer Tasks with 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#)
- Get NAnt from http://prdownloads.sourceforge.net/nant/nant-0.85-bin.zip?download
- Get NAntContrib from http://prdownloads.sourceforge.net/nantcontrib/nantcontrib-0.85-bin.zip?download
- Extract NAnt in “C:\Program Files\NAnt”
- Extract NAntContrib\bin in “C:\Program Files\NAnt\bin”
- Create a NAnt.bat file in C:\Windows with the following:
@echo off
“C:\Program Files\NAnt\bin\nant.exe” %* - 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.
<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>
- Login or register to post comments
- 860 reads
- Flag as offensive
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Matthew Schmidt replied on Wed, 2008/01/30 - 10:35pm
Boyan Kostadinov replied on Thu, 2008/01/31 - 8:47am
in response to: matt
Sebastian Jancke replied on Thu, 2008/01/31 - 4:20pm
Hey matt, hey boyan
have a look at my recent blogentry: http://www.dzone.com/links/improving_agility_in_visual_studio_2005.htm. It provides good integration of NAnt into Visual Studio (seems the only one available).
Boyan Kostadinov replied on Thu, 2008/01/31 - 10:04pm
@Sebastian, sweet, thanks! I was going to write about integration with Visual Studio but my way was no way nearly as nice as these Visual Studio add-ins.
------------------
Boyan Kostadinov
Blog: http://blog.tech-cats.com
Resume: http://boyan.tech-cats.com/resume
Portfolio: http://boyan.tech-cats.com/portfolio