"MyService.exe install" not performing installation of service

113 views
Skip to first unread message

Robert Wade

unread,
Nov 28, 2017, 2:19:08 PM11/28/17
to topshelf-discuss
I've created a C# console application and am attempting to use TopShelf to assist in deploying the application as a service. In my Main method I have the following code:

HostFactory.New(x =>
{
  x.Service<BusinessLogic>(s =>
  {
    s.ConstructUsing(name => new BusinessLogic());
    s.WhenStarted(tc => tc.Start());
    s.WhenStopped(tc => tc.Stop());
  });

  x.RunAsLocalSystem();
  x.StartAutomatically();

  x.SetDescription("Business Logic");
  x.SetDisplayName("BusinessLogic");
  x.SetServiceName("BusinessLogic");
});

After I build, I open an administrator command prompt and enter "BusinessLogic.exe install" and get the following output:
Configuration Result:
[Success] Name BusinessLogic
[Success] Description Business Logic
[Success] ServiceName BusinessLogic
Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000

I didn't realize it at first, but based on various Google searches I now see that this output is missing the installation portion of the "install" process.

If I enter "BusinessLogic.exe help" I get the exact same output.

The service is obviously not installed. Any help is appreciated.
Rob


Robert Wade

unread,
Nov 29, 2017, 1:07:42 PM11/29/17
to topshelf-discuss
The solution is simple. On the first line I should have used "HostFactory.Run" instead of "HostFactory.New"

The documentation correctly shows the use of .Run() in the first example but then use .New() for the remainder. That is why I went astray.
Reply all
Reply to author
Forward
0 new messages