Oct 19, 2007 / software ~ .net
.NET Console Apps Rock

Console apps are underrated in my opinion, especially in the Windows world. When working with different developers, I often find that they often build their small utility programs as WinForms apps.

I used to do this, but over the last 5 years I've found myself building Console apps more and more. Basically, if I want my code to be reapeatable or schedulable, then Console apps are my first port of call.

By using batch files, I can run a program in rapid succession with a bunch of preset parameters.

# runme.bat
SpiderWebSite.exe site=http://www.tobinharris.com depth=3 
SpiderWebSite.exe site=http://www.socena.com depth=*
SpiderWebSite.exe site=http://www.tobinharris.com depth=3

Similarly, if I want to be able to run my tasks on a schedule, then I can set up a Windows Scheduled task to kick off my Console app whenever I want:

#RunMeInAtMidnight.bat
FileGrabber.exe mode=ftp location=ftp://www.somesite.com authfile=auth.xml
ETL.exe source_folder=c:\temp dbfile=db.xml transforms=transforms.xml

And if the windows scheduler doesn't float your boat, then you can use alternatives like CRONw or pyCron.

A pretty GUI is certainly the right way to go in many situations, like where a non technical user is involved. But, if you're donig ETL (Extract Transform & Load), web spidering, batch conversions etc, the console is a great start.

Solution Structure

If you're convinced that console apps are a "good thing", then here's a handy Visual Studio solution structure that gives you a lot of flexibility

- MyProgram (Solution)
  - MyProgram.Console (Console Project)
  - MyProgram.Core (DLL Project)
  - MyProgram.UnitTests (DLL Project with NUnit)
  - MyProgram.GUI (optional WinForms project giving a pretty UI if needed)
  - MyProgram.Web (optional Web Site project, again giving a pretty UI if needed) 

You may also like...