.Net Core 2.0 Windows Service

前端 未结 10 1356
谎友^
谎友^ 2021-01-30 01:25

I\'m trying to build a Windows Service in .Net Core 2.0 but I\'ve been banging my head on the wall for a full day and no progress at all. Everything seems to be using Core 1.0/1

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 02:16

    I'll summarise some options:

    1. Move your code into a .NET Standard library, and host it in a .NET Framework app, so you can use ServiceBase. This will of course need the .NET Framework to be installed on the target machine
    2. Use NSSM (the Non-Sucking Service Manager) to manage a .NET Core console app (it has a public domain license)
    3. Use Windows API calls to hook into Windows service methods. This is the approach taken by DotNetCore.WindowsService and dotnet-win32-service (both are MIT licensed)

    I think @JeroenMostert's comment is a bit harsh - I can see the appeal of not being dependant on a particular .NET Framework version being available on the target machines. Plenty others obviously feel the same, as the 2 repos I linked to are rather popular.

提交回复
热议问题