What is nAnt, and how it can be useful to me as a C# developer?

Fitzchak Yitzchaki picture Fitzchak Yitzchaki · Jan 24, 2010 · Viewed 9.5k times · Source

I'm always compile my project, and copy the dll's from the dependency projects to the UI bin folder. after a few days with 'copy & paste' operations each time that I recompile my project, I concluded that I need a tool that will do it to me automatically. after a few searches a founded that this tool is nAnt.

I search for information how to start using it, but I did not found much. so, my question is:

  • What is nAnt in a few words?
  • How can I benefit from it?

EDIT: I can't just add a reference to the dependencies projects because it will lead to a circular dependency.

Answer

Tony Heupel picture Tony Heupel · Jan 24, 2010

NAnt is a build tool that builds .NET projects and solutions (based on the original Ant for Java). It is also an XML-based "scripting" language where you order "tasks" to do the build work, including the types of things you are talking about--and MUCH, MUCH more!

We use NAnt as our build scripting tool (triggered on every source-control checkin by Cruise Control.NET, a.k.a. CCNET, our Continuous Integration tool) to do our automated builds. It includes things like:

  1. Building the solution
  2. Running our Unit Tests to make sure the build didn't "break"
  3. Deploying our web project to our development server
  4. Zipping and archiving a build into a build folder for historical tracking and "backout"

Another solution is MSBuild, which is actually what Visual Studio uses. It is very similar.

Do note: You CANNOT build Setup & Deployment projects with NAnt's solution task (you also cannot do this with MSBuild). To get around this, we have started running devenv.com (Visual Studio without a UI) with command-line arguments--using NAnt's "exec" task instead of the built-in "solution" task--to build the whole solution, including Setup & Deployment Packages. We have also uses WiX and MSBuild in the past...

Finally, for the specific issue you outline, you should really just consider one of these options:

  • Simply add the dependent projects to the Web Site solution as Project References and you will get the DLLs there automatically
  • Consider creating a PostBuild task (look on the Project Properties window) that does an xcopy on a successful build

You really can't go wrong investing time in NAnt, and eventually CCNET as your project complexity increases. You can have CCNet watch your source control for checkins or run nightly, AND you can set up dependent projects, so that, for example, if your dependency project builds, it can kick off a build of your web site and/or run Unit Tests to see if anything broke.