Can I register netcore2 Topshelf application as Windows service on Windows?

184 views
Skip to first unread message

Xi Shen

unread,
Nov 2, 2018, 1:38:40 AM11/2/18
to topshelf-discuss
Hi,

I understand Topshelf netcore2 support is still in developing. I created a simple Topshelf netcore2 service like below.

  class Program
 
{
   
static void Main(string[] args)
   
{
     
var containerBuilder = new ContainerBuilder();
      containerBuilder
.RegisterType<ShellService>();


     
var container = containerBuilder.Build();


     
HostFactory.Run(configurator =>
     
{
        configurator
.UseAutofacContainer(container);
        configurator
.Service<ShellService>(settings =>
         
{
            settings
.ConstructUsingAutofacContainer();
            settings
.WhenStarted(service => service.Start());
            settings
.WhenStopped(service => service.Stop());
         
}
       
);
        configurator
.SetDescription("Shell Service");
        configurator
.SetDisplayName("Shell Service");
        configurator
.SetServiceName("Shell Service");
     
});
   
}
 
}


Then I tried to install the service with an Admin console.

dotnet
Nike.Service.Shell.dll install

The error I got was like below.

Topshelf.HostFactory Error: 0 : An exception occurred creating the host, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: ARGUMENT: install
[Success] Name Shell Service
[Success] ServiceName Shell Service
   at
Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable`1 results)
   at Topshelf.HostFactory.New(Action`
1 configureCallback)
Topshelf.HostFactory Error: 0 : The service terminated abnormally, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: ARGUMENT: install
[Success] Name Shell Service
[Success] ServiceName Shell Service
   at
Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable`1 results)
   at Topshelf.HostFactory.New(Action`
1 configureCallback)
   at
Topshelf.HostFactory.Run(Action`1 configureCallback)



But according to this article, https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1, registering a netcore2 application as a Windows service is possible. So I wonder if I miss anything, or Topshelf has not supported this feature yet.


Thanks,
David


Reply all
Reply to author
Forward
0 new messages