Post Build events and NAnt build failures

Found a gotcha with NAnt and Visual Studio .NET 2003.
If you have specified a post-build event in the project properties (e.g. like a file copy operation - copy A.txt \executables) AND you have used the OutputDir attribute for the solution task in your NAnt build script (e.g. you want the built executables to go into another folder than the one specified in the proj properties) you'll run into build failures.


< solution configuration="${BuildConfig}" solutionfile="${ImportUtil_SlnPath}" outputDir="\executables" verbose="true">

The project will build correctly under the IDE but not under NAnt. This is because of the difference in current directories in both cases.


1. When run from the IDE, the path from which the postbuild batch is executed is [ProjectDir]\bin\debug (or release)
2. When run from NAnt, the path would be \executables (i.e. the OutputDir attribute value)
Hence the copy command can't find the source file and fails the build.

Lessons Learnt:

  • Post build events are not recommended - use NAnt build script as the single point where all such tasks are documented. Post build events are hidden inside property pages and hence are difficult for someone new to find out. This however means that the entire team makes a commitment to use Nant (bye bye IDE builds).
  • Do not use OutputDir attribute if you still use Pre/Post build events. :)

In the end I took option 2 to get my CI server back to Green

No comments:

Post a Comment