Search code examples
.nettopshelf

TopShelf Not Responding to Command Line Arguments


The TopShelf documentation says that MyService.exe will respond to a range of command line arguments. However, the documentation also shows absolutely no indication that command-line parameters are being consumed by the main program.

Apparently this is working for everyone, because I've found no discussion of this problem anywhere. And yes, unsurprisingly, when I try to execute MyService.exe help I get no response; it is not working for me.

I would expect the sample link above would at least contain the usual args formal parameter...

static void Main(string[] args) {...}

But it does not. What am I missing?

Update

I discovered the problem: the console application I had created in Visual Studio was somehow corrupt. After deleting it and recreating it, the problem was resolved.


Solution

  • Internally TopShelf uses the BCL Environment.CommandLine property, which contains command line arguments, passed to your app. It's their design decision not to require command line arguments to be passed in explicitly.

    For help problem you could try

    HostFactory.Run(configurator =>
    {
        configurator.AddCommandLineDefinition("yourCommand", f=> { /*some action*/});
        configurator.ApplyCommandLine();