When building a console app with the csc task in NAnt, set the correct target

Today, I crafted some XML to build a console application using a csc task in NAnt. The app built fine (hooray), but then I spent the best part of the afternoon trying to work out why I kept getting the following error when trying to run the application:

After some sanity checks I then googled the error description, which lead me down the path of checking my dependencies. They were all accounted for in the XML. I opened the app in Reflector and all looked fine: the dependencies were all there, and all the assembly versions being referenced were correct. I repeated this process until my mind started contemplating chaos theory.

So what was the solution? Besides jumping in front of the nearest double decker bus? Well, after much banging of head on table, it came down to a simple cut and paste bug. I had inadvertently set the target of the csc task to be “winexe” instead of “exe” (winexe is also a valid option, but simply not the correct target option for a console app). I changed this, rebuilt and all was fine.