dasMulli / dotnet-win32-service

Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
MIT License
451 stars 57 forks source link

Support for Net.core 1.1.0 projects #15

Closed jersiovic closed 7 years ago

jersiovic commented 7 years ago

Hi, first of all many thanks for sharing this code. I've been using successfully your library for executing as a windows service a Net.Core 1.0.1 project. Problem is when I updated the project to Net.Core 1.1.0 I receive a weird error message when the app services starts: Error: 0xfffffffff 0xffffffff.

Maybe the reason is your library doesn't support Net.Core 1.1.0. If that is the reason, do you plan to support it?

dasMulli commented 7 years ago

I didn't yet try to upgrade the sample project but yes i do plan to support it.

jersiovic commented 7 years ago

Great :)

dasMulli commented 7 years ago

So i just updated the test service to 1.1 (see the feature/aspnetcore-1-1-0-upgrade branch) and that passes smoke testing. (Just waiting for appveyor to update their images so i don't have to add a custom download build step) Do you maybe have a repro code for your error?

You could also run into an initialisation error with asp.net core 1.1 making your Start() method throw. This currently makes the service report -1 / 0xffffffff to windows here.

jersiovic commented 7 years ago

I'm using your library to allow execute Orchard CMS as windows service. This is the branch where I'm using it https://github.com/OrchardCMS/Orchard2/tree/runAsAService . The point is when I execute it in standalone mode it works properly despite Start code is very similar when it is run as a service instead of standalone. https://github.com/OrchardCMS/Orchard2/blob/runAsAService/src/Orchard.Cms.Web/OrchardCmsWin32Service.cs#L47 The start project is Orchard.Cms.Web For building it you need to execute: ´build.cmd´ from root folder For publishing it from \src\Orchard.Cms.Web folder dotnet publish --configuration Release --output c:\OrchardCMS For running it fromc:\OrchardCMS\ folder dotnet orchard.cms.web.dll --register-service -urls http://localhos:5000

But if you prefer a simpler repro project tomorrow I will try to reproduce it in a more simple one.

dasMulli commented 7 years ago

So if i follow your exact instructions i get an exception because it is meant to be --urls and not -url (one dash):

The short switch '-urls' is not defined in the switch mappings.
   at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Orchard.Cms.Web.OrchardCmsWin32Service.Start(String[] startupArguments, ServiceStoppedCallback serviceStoppedCallback)

If i leave that out, it works for me.. (at least it starts, i didn't invest time to make the right node version work that was used by the build).

jersiovic commented 7 years ago

Oh my god!! I didn't noticed I made this typo Thank you!

dasMulli commented 7 years ago

Glad to hear your issue is resolved 😄

My learning from this is that maybe the additional parameters passed to --register-service should be checked before registering them.. maybe the CommandLineConfigurationProvider class from the Microsoft.Extensions.Configuration can be used to perform basic validation (an invalid URL passed to --urls will still fail. just like it will fail when the port is already in use).

Besides, you should consider updating the Microsoft.Extensions.Configuration to 1.1.0 as well.