5

I am currently using Visual Studio for Mac and I need to create a background running service application. I realised that the only option that I have is the Console Application in VS Mac. The exe that I will create should run as a Windows Service when deployed to a Windows server or a daemon process in a Linux server.

Can achieve this with Net Core? Is it possible to create a cross platform service process with Visual Studio for Mac?

thus
  • 1,326
  • 1
  • 14
  • 23
  • https://learn.microsoft.com/ro-ro/visualstudio/productinfo/vs2017-compatibility-mac#platform-targeting and https://stackify.com/cross-platform-net-core-apps/ So basically, yes, you can – ares777 May 09 '19 at 08:29
  • This doesn't answer the question. Those two links show what @thus and I already know - you can write Windows Applications on MacOS and it will run on either OS. What it doesn't answer is whether or not you can create a Windows Service in Visual Studio for Mac. Specifically, the first link you provided said "Visual Studio for Mac does not support Windows client projects like Windows Forms, WPF, or UWP". It doesn't say anything about Windows Service applications, but logically I can see how this might be a problem. I haven't found a solution. – aradil Jul 04 '19 at 12:25

1 Answers1

4

Yes you can. With .net core 3.1, you can create a project using the "Worker Service" template. Then install the Microsoft.Extesions.Hosting.WindowsService nuget package and add UseWindowsService() to the CreateHostBuilder method.

You can see a more detailed answer in this post:Building a Windows service with Worker Services and .NET Core 3.1, part 1: Introduction

RCKSTR
  • 86
  • 8
  • I remember I asked this question around 1 year ago and in those days .Net Core didn't have this. My solution was using Topshelf and it saved me. Thank you for your answer. I didn't test / integrate the .Net Core 3.1 solution that you suggested but I will accept your answer. I am sure it is easier to use than Topshelf. – thus Apr 13 '20 at 21:24
  • I've switched a few weeks ago from Topshelf to use native approach of .Net Core and it's only one line on configuration. I have two projects: one for Windows Service, second for Deamon on Linux with logic in separated project. It work's very well. – Jacek Labuda Aug 14 '20 at 06:53