0

I am trying to run a .net Core app on top of the .net Core Runtime, but in a Windows service.

I'm not trying to run the library on the full .net Framework (it wouldn't work anyway at the moment since it's ASP.net Core 2.0 Preview 1), and my next best attempt would be to use a System.Diagnostics.Process.

I'm really just trying to find a way to wrap a console application in the Start/Stop methods and authentication scheme of a Windows Service, but because that Console Application happens to be .net Core, I wonder if I can just Host the runtime itself (e.g., some P/Invoking). I know that C++ apps can host the full runtime, but I haven't seen if such a mechanism exists for .net Core.

Has anyone tried that? Maybe some C++/CLI magic if a pure C# approach wouldn't work?

1 Answer 1

3

Hosting the runtime is a considerable effort since you'd need to handle the resolution logic for native and managed libraries.

You can do either:

  1. Launch the .net core app as sub-process using Process.Start(..) - e.g. run the dotnet.exe process with the dll as argument.
  2. Turn the .net core console app into a windows service. Since ServiceBase isn't available on .NET Core (yet), I've created a wrapper API on top of the necessary windows API calls: https://github.com/dasMulli/dotnet-win32-service (follow readme for more detailed instructions)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, that wrapper looks like what I'm after. I will give it a try on the weekend and let you know!
Do that, feedback & GitHub issues welcome. (Most frequent problem: windows services always start in C:\Windows\system32 and fail to load config like appSettings.json)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.