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

thu*_*hus 5 windows-services .net-core visual-studio-mac

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

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

小智 4

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

您可以在这篇文章中看到更详细的答案:使用 Worker Services 和 .NET Core 3.1 构建 Windows 服务,第 1 部分:简介