是否可以使用 Visual Studio 为 Mac 创建 Windows 服务?

Is it possible to create a Windows Service with Visual Studio for Mac?

我目前正在为 Mac 使用 Visual Studio,我需要创建后台 运行ning 服务应用程序。我意识到我唯一的选择是 VS Mac 中的控制台应用程序。当部署到 Windows 服务器或 Linux 服务器中的守护进程时,我将创建的 exe 应该 运行 作为 Windows 服务。

用Net Core可以实现吗?是否可以使用 Visual Studio for Mac 创建跨平台服务进程?

是的,你可以。使用 .net core 3.1,您可以使用 "Worker Service" 模板创建项目。然后安装Microsoft.Extesions.Hosting.WindowsService nuget包,在CreateHostBuilder方法中添加UseWindowsService()

您可以在post中看到更详细的答案:Building a Windows service with Worker Services and .NET Core 3.1, part 1: Introduction