Adding Custom Arguments to Topshelf

07 dez 2016

Topshelf is an amazing framework that let you easily host and build Windows services.

Topshelf is really extensible, but recently I struggled to find how to configure a custom argument to the service.

This post is simple tip to help you create custom arguments to a Topshelf service and use it in the command line.

This can be accomplished simply using the Host Configurations.

If you use the method "AddCommandLineDefinition" you will be able to specify the name of your argument (case sensitive) and how you want to use it.

You can find here a simple example.

Then you can execute your service sending your argument as you can see in the following example (command line invoke).

.\TopShelfCustomArgs.exe run -path:"c:\temp" -frequency:2 

Hope this helps.

comments powered by Disqus