example project with apublished executable fails to run as a service
jgreene opened this issue · 2 comments
When using a publish command like:
dotnet publish "C:\dev\projects\opensource\dotnet-win32-service\samples\TestService\TestService.csproj" -c Release -r win10-x64 -o "C:\dev\projects\opensource\dotnet-win32-service\samples\published\TestService"
and registering the resulting .exe as a windows service
sc.exe create TestService DisplayName= "TestService" binpath= "C:\dev\projects\opensource\dotnet-win32-service\samples\published\TestService\TestService.exe"
attempting to start the service results in:
Error 1053: The service did not respond to the start or control request in a timely fashion.
If I register it with dotnet.exe it works fine. I would prefer it if a dotnet.exe installation wasn't required to run the windows service. Is this behavior intended?
So the test application actually needs --run-as-service
as an additional parameter..
The idea was that you could replace the sc.exe
call by using TestService.exe --register-service
and it should detect if it is self-contained or a "portable" app run by dotnet.exe and "do the right thing".
Running it without arguments just prints a description and exits, which doesn't make the windows service system very happy 😉
I do think that does get lost a bit with the README's description showing something much simpler..
using --run-as-service seems to have resolved the issue. I was hunting down why a much more complex application wasn't working when starting up as a windows service and thought I had come up with a minimal example (I was obviously wrong). It turns out that my application wasn't working because I set Console.Title which seems to prevent the windows service from starting.