About Me

Training

Nothin But .Net Developer Bootcamp

Navigation

Search

Categories

On this page

Clean up your (NAnt) build files by taking advantage of fileset references

Archive

Blogroll

 Agile Developer Venkat's Blog
 Ayende @ Blog
 B#
 Barry Gervin's Software Architecture Perspectives
 Boy Meets World
 Brad Abrams
 Canadian Developers
 Christopher Steen
 Claritude Software News
 Clemens Vasters: Enterprise Development and Alien Abductions
 Coding Horror
 Coding in an Igloo
 Dare Obasanjo aka Carnage4Life
 Darrell Norton's Blog [MVP]
 David Hayden [MVP C#]
 Don Box's Spoutlet
 Eric Gunnerson's C# Compendium
 EZWeb guy: Jeffrey Palermo [C# MVP]
 Fear and Loathing
 Generalities & Details: Adventures in the High-tech Underbelly
 Greg Young [MVP]
 Greg's Cool [Insert Clever Name] of the Day
 IanG on Tap
 Ingo Rammer's Weblog
 ISerializable - Roy Osherove's Blog
 James Kovacs' Weblog
 Jason Haley
 Jean-Luc David
 Jeremy D. Miller -- The Shade Tree Developer
 JetBrains .NET Tools Blog
 Jimmy Nilsson's weblog
 John Bristowe's Weblog
 John Papa [MVP C#]
 Jon Skeet's Coding Blog
 JonGalloway.ToString()
 Jump the Fence or Walk Around
 Lambda the Ultimate - Programming Languages Weblog
 Larkware News
 Lutz Roeder
 Marquee de Sells: Chris's insight outlet
 Martin Fowler's Bliki
 Mike Nichols - SonOfNun Technology
 MSDN Magazine - .NET Matters
 MSDN Magazine - All Articles
 OdeToCode Blogs
 Onion Blog
 Planet TW
 Raymond Lewallen [MVP]
 Rockford Lhotka
 RodMan's Corner
 Roger Johansson's blog
 Sahil Malik - blah.winsmarts.com
 Sam Gentile's Blog
 Scott Bellware [MVP]
 Scott Hanselman's Computer Zen
 ScottGu's Blog
 secretGeek
 Service Station, by Aaron Skonnard
 Signum sine tinnitu--by Guy Kawasaki
 Stephen Toub
 Steve Eichert's Blog
 Steven Rockarts
 The Blog Ride
 The Coding Hillbilly
 The Daily WTF
 TheServerSide.net: News
 Tim Gifford
 Vance Morrison's Weblog
 you've been HAACKED

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 519
This Year: 28
This Month: 0
This Week: 0
Comments: 1593

 Wednesday, November 01, 2006
Wednesday, November 01, 2006 8:17:07 PM (Mountain Standard Time, UTC-07:00) ( Agile | Tools )

Imagine you have a buildfile and you have the following compile element that makes use of a couple of third party assemblies:

 

        <csc target="library" output="${dist.dir}\${app.library.name}" debug="${debug}">
            <sources>                
                <include name="${app.src.dir}\**\*.cs" />                
                <exclude name="${app.src.dir}\**\AssemblyInfo.cs" />
            </sources>    
            <resources>
                <include name="${config.dir}\mapping\*hbm.xml"/>
            </resources>
            <references>
                <include name="${lib.dir}\filehelpers\DotNet 2.0\FileHelpers.dll"/>
                <include name="${lib.dir}\binsor\Castle.Windsor.dll"/>
                <include name="${lib.dir}\log4net\log4net.dll"/>
                <include name="${lib.dir}\nhibernate\NHibernate.dll"/>
            </references>
        </csc>
 

Pay close attention to the references element. Notice how I am explicitly including the names of libraries that I want to  that "references" fileset.

Most people who are using NAnt are familiar with the concept of a fileset. Essentially it is a set of files that belong to a logical unit that you can make use of during the NAnt build process.

Assume I have another target that needed to perform a similar compile. I could just copy the references element, but that would be unnecessary duplication. What I can do is create a fileset that can be later referenced and used by other targets/tasks in the build file.

 

I'll start by creating the filset near the top of my build file (before any targets):

 

    <fileset id="deploy.lib.fileset">    
        <include name="${lib.dir}\filehelpers\DotNet 2.0\FileHelpers.dll"/>
        <include name="${lib.dir}\binsor\Castle.Windsor.dll"/>
        <include name="${lib.dir}\log4net\log4net.dll"/>                
        <include name="${lib.dir}\nhibernate\NHibernate.dll"/>                                
    </fileset>

 

Notice how I have changed the element to be of type filset vs references. The references element is a special subclass of fileset reserved for the csc task. You will also notice how I have given the fileset an id. It is this id that will allow me to reference this fileset elsewhere. I can now replace the fileset I was originally using in the csc task with a reference to the fileset that contains all of the references that should be used for the compile task:

 

        <csc target="library" output="${dist.dir}\${app.library.name}" debug="${debug}">
            <sources>                
                <include name="${app.src.dir}\**\*.cs" />                
                <exclude name="${app.src.dir}\**\AssemblyInfo.cs" />
            </sources>    
            <resources>
                <include name="${config.dir}\mapping\*hbm.xml"/>
            </resources>
            <references refid="deploy.lib.fileset"/>                
        </csc>

  

You can see now that the references element in the csc task now uses the refid attribute to link back to a fileset that I have already defined elsewhere in the build file. Think how many filesets you may take advantage of when building your apps using NAnt:

  • sources
  • references
  • resources

And that is just a small sample. Streamlining and refactoring the build file is just as important as refactoring and improving the code base of the app that the build file is building.

Hopefully this has given you one more tool with which you can go and clean up some duplication that may exist in your build file.