Monday, April 30, 2012

A Better Starting Point for .Net Console Applications

Often when prototyping .Net applications, I end up starting with a console app (as things get more complicated or require interactivity, I move to Windows forms).  It takes about 1 minute to get up and running with a console app. . . unless you want to start passing fancy parameters and things like that.  It doesn’t take much more effort, but the point is that you don’t want to re-invent the console app code, you want to spend your time prototyping.

Sometimes your production application might require a console app.  In my case, one portion of the application I am working on will need to be implemented as a console app (for now) so that it can be executed from a SQL Server Agent job.  I want the console app to be robust and production-ready, very different from the prototype apps I cobble together in the span of a couple of minutes.


In support of a more robust console application, I found a blog post with a great template put together by Alois Kraus.  There is a blog post covering the basics, and the template can be downloaded from the Visual Studio Gallery.

At a high level, the custom console template starts you off in a Cadillac instead of a bicycle when building a console application.  Right out of the gate you get a nice command line parser, help output, color console and much more robust error handling.  I doubt I will start with the basic console template again.

No comments: