1

I haven't built many console apps, but I noticed that command-line args are ignored when the .exe was created with Visual Studio 2013's publish feature. The .exe in the project /bin/debug folder acknowledges command-line args.

I created this test console app because I couldn't get command-line args with a few example(s) of a self-installing windows service.

What am I missing?

Here is my simple console app:

class Program
{
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("arrrrrrrrrrrgggggggg!");
        }
        else
        {
            for (int i = 0; i < args.Length; i++)
                Console.WriteLine("Arg: {0}", args[i]);
        }


        Console.ReadLine();

    }
}
Viracocha
  • 33
  • 2
  • Seems like you're a little confused. On VS you can put command-line args on project preferences in order to quick debug, but when you publish your app, you need to supply the params manually. You can use a shortcut link. – Mr Rivero Oct 24 '15 at 01:13
  • hmm..maybe I'm confused, but I thought calling the app from the command prompt would pass the args: (myConsoleApp.exe arg1 arg2 arg3). but, it only works with the /bin/debug folder version. It does not work when I use Publish. – Viracocha Oct 26 '15 at 19:55

1 Answers1

0

Publishing a console app does not disable command line arguments. In Visual Studio, you can add command line args in the project properties or some place like that. However, when you publish the app, the app is standalone. Visual Studio cannot do things like adding command line args to the app. You have to do it yourself.

Instead of clicking on the .exe file, you first run cmd.exe. In the console, you write a command to run your app. Forgive me, I don't remember exactly what command you will have to use. After the command, you can start adding command line args, separated by spaces!

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • That's what I've been doing, though. I've running from the command prompt: myConsoleApp.exe arg1 arg2 arg3. The args get passed when using the .exe version in the /bin/debug/ folder, but it does not work with the version that gets created by using VS2013 publish feature. – Viracocha Oct 26 '15 at 20:01