C# – Showing help for a command-line utility

.net-2.0c++visual-studio-2008

I have a command-line utility that gets quite a bit of downloads from my site. I'm trying to show the usage when a user uses the /? or /help parameters. I have a function called ShowUsage() that has nicely formatted text on the parameters available.

I see that ShowUsage() gets called fine from Visual Studio 2008, when I'm using the command-line parameters in the project properties. However the exe does not display the help text when run from the command-line. Here's a shortened version of ShowUsage():

private static void ShowUsage()
{
    Console.WriteLine(Environment.NewLine);
    Console.WriteLine("Text File Splitter v1.4.1  released: December 14, 2008");
    Console.WriteLine("Copyright (C) 2007-2008 Hector Sosa, Jr");
    Console.WriteLine("http://www.systemwidgets.com");
    Console.WriteLine("");
}

I tried a bunch of different things from my searches in Google, but none are working. I know this has to be something simple/easy, but for the life of me, I can't figure this one out.

EDIT:

The code that calls ShowUsage():

if (!Equals(cmdargs["help"], null) || !Equals(cmdargs["?"], null))
{
    ShowUsage();
}

I have a class that parses the parameters into the cmdargs array. I confirmed that the parameters are in the array. It's something inside ShowUsage() that is preventing from showing the text.

I'm going to try the debug trick, and see what I find.

I'm not using Console.Out anywhere.

d03boy – Just personal preference. It makes the text less cluttered onscreen, at least to me.

EDIT #2

Ok, some more information… I'm running VS2008 in Vista Ultimate 64 bit. I just check the project properties and it is set to "Windows Application." This utility is 32 bit.

I'm going to experiment with creating a separate project in the solution that is a true console program, as some of you have advised.

Best Solution

Can you define "not working"? Simply not doing anything? Throwing an exception? I would expect the problem to be in the Main(...) method - i.e. ShowUsage() isn't being called. Another common issue is not rebuilding it in the correct configuration, so bin/release (or whatever) isn't updated.

Have you built the app as a console exe? i.e. is the "Output Type" = "Console Application" in project properties? It needs to be in order to access the console...

For info, I find the easiest way to do a console help screen (once it gets beyond a handful of lines) is to embed a .txt file into the exe; then I just write out the text file (perhaps still using string.Format if I want to replace tokes).

Alternatively, there is the alternative string format:

    Console.WriteLine(@"
Text File Splitter v1.4.1  released: December 14, 2008
Copyright (C) 2007-2008 Hector Sosa, Jr
http://www.systemwidgets.com

");