我目前正在使用Visual Studio for Mac,我需要创建一个后台运行的服务应用程序。我意识到,我唯一的选择是VS Mac中的控制台应用程序。部署到Windows服务器或Linux服务器中的守护进程时,我将创建的exe应该作为Windows服务运行。
使用Net Core可以实现吗?是否可以使用Visual Studio for Mac创建跨平台服务过程?
是的,可以。使用.net core 3.1,可以使用“ Worker Service”模板创建项目。然后安装Microsoft.Extesions.Hosting.WindowsService nuget程序包,并将UseWindowsService()
添加到CreateHostBuilder
方法。
您可以在这篇文章中看到更详细的答案:Building a Windows service with Worker Services and .NET Core 3.1, part 1: Introduction