Reputation: 110
I need to create a Windows Service on a Windows machine, but the system will have only .NET Core 2.0. The Windows Compatibility Pack now supports System.ServiceProcess.ServiceBase, so this should be possible. I've installed the NuGet package for the WCP, but am at a loss as to how to get started with started with developing a service.
In .NET Framework, there's a wizard for creating an initial service framework, which I have used. However, I'm not sure how to either (1) create a new .net core service from scratch using the WCP, or (2) take a .net Framework service and convert it to use .net Core - there is no way to retarget in the Project properties.
I've tried forcing retargetting by editing the appconfig to reference netcoreapp2.0, but the project still references .net framework assemblies.
The package is Microsoft.Windows.Compatibility -Version 2.0.0-preview2-26406-04
I'm kind of new to this, and would appreciate any suggestions.
Upvotes: 2
Views: 1138
Reputation: 16685
As luck would have it, I've recently written a blog post on just this subject.
Basically:
Create the app as a .Net Core console application.
Install the Windows Compatibility Pack (Install-Package Microsoft.Windows.Compatibility
).
Create your service by inheriting from ServiceBase (class TestSevice : ServiceBase
).
In the Main method of your console app, just instantiate the service and call run (ServiceBase.Run(service);
).
In order to install it, use sc.exe.
Upvotes: 1