Code, photos, books, and anything else

Subscribe to my RSS feed

.NET Projects: Packaging Your Build


In the past, I’ve talked about using NAnt to automatically prepare and build your application. The use of NAnt does not end once the compile has completed, however. Sure, you’ll want to run tests and analyses, generate documentation and so on, but the end point of the cycle is usually packaging the artifacts for distribution. I’ll show a task that can be used to generate a Zip file of your build results.

This is a follow-up to my recent post, Revisiting NAnt for Builds. That post outlines my current standard build file, including a number of tasks, one of which is for packaging build artifacts for distribution. This post covers the package task in some detail.

Packaging in Zip Files

Probably the simplest way to package build artifacts is by putting them all into a Zip file. Zip files are widely used and understood, and NAnt creates Zip packages with hardly any effort.

Below is the entire package task that I have in my build file. It makes use of NAnt’s zip task – take a look at the sample below, an explanation follows.

[code lang="xml"]


The zip task’s zipfile attribute looks complicated, but it is just joining some project property values to form the filename for the resulting Zip file. Such a filename after running the task looks like It consists of, among other things, the project name and the version number. The fileset element’s basedir attribute indicates the base directory where the to-be-packaged files are located, namely, the build directory. The elements within indicate which elements are to be included in, or excluded from, the resulting Zip file. The include element is a general catch-all directive, while the exclude elements indicate certain elements to be excluded (the Zip package doesn’t need the test files, or the NUnit framework, or the project’s XML documentation files).

For more details on the zip task’s properties and sub-elements, have a look at the NAnt documentation.

Below is a screenshot of the command window after having run the package task of the build file. The red lines in the image indicate the items of interest. At the top, the package target has been invoked. Clearly, some prerequisite work is done first. Then, near the bottom, the task is run, and shows the result.

Command line window showing packaging taskThe result of the package task when run on the command line

And following is a shot of the project root directory where the resulting Zip file has been generated. The resulting Zip file has been underlined in red.

Zip file generated by package taskProject root directory has new Zip file containing build artifacts

And that is the zip task in a nutshell. It’s simple, takes hardly any work to set up, and can be executed with one command. As an additional note, a Zip file is not the only option. NAntContrib has an msi task (documentation) to create an installable file for Windows systems. Given NAnt’s flexibility and extensibility, it is likely that there are custom tasks available that will handle other deployment formats for you.

Back to the Zip task, you don’t need to limit yourself to a single Zip file per build. In some situations, you may want to package project documentation in a separate file, or perhaps even the source code (likely in the case of an open source project). The package target can execute the zip task multiple times, for different distributions of files. In my example, I just packaged the binary executable files, as that is the only distribution option I need at this point.


This has been a relatively simple portion of the series, but is no less important than any other part. You need to have a way to easily distribute build artifacts; NAnt provides a gateway to gathering files and packaging them in a useful format. There are a number of such formats, including Zip, MSI, EXE, and ClickOnce. I showed the built-in Zip technique, since that is the simplest and, in a lot of cases, probably sufficient. However, the technique shown is easily modified, simply by replacing the default packaging task in the build file with one to suit your needs.





Comments closed

Leave a Comment

Apologies, commenting is now disabled for this post.