DH.NAgent 4.18.2026.210

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package DH.NAgent --version 4.18.2026.210
                    
NuGet\Install-Package DH.NAgent -Version 4.18.2026.210
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DH.NAgent" Version="4.18.2026.210" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DH.NAgent" Version="4.18.2026.210" />
                    
Directory.Packages.props
<PackageReference Include="DH.NAgent" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DH.NAgent --version 4.18.2026.210
                    
#r "nuget: DH.NAgent, 4.18.2026.210"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DH.NAgent@4.18.2026.210
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DH.NAgent&version=4.18.2026.210
                    
Install as a Cake Addin
#tool nuget:?package=DH.NAgent&version=4.18.2026.210
                    
Install as a Cake Tool

DH.NAgent - 守护服务管理组件

功能特点

DH.NAgent是一个服务管理框架,用于开发随系统自动启动的长时间运行后台应用程序,支持Windows/Linux。
在Windows上注册为Windows服务,在Linux上注册为Systemd守护进程。
Agent支持netstandard2.0/net45/net40/mono,旧版本还支持net20(已不再维护)。

Agent常用于各种后台应用,如aspnetcore应用、RPC网络服务器、MQTT服务器、数据处理应用、数据消费应用(Redis/RocketMQ)等。同类软件有 NSSM、srvany,但并不一样,Agent是框架,而它们是具体软件,更像星尘代理 StarAgent。

DH.NAgent主要功能:

  1. 注册应用为系统服务或守护进程,随系统自动启动
  2. 支持控制台菜单控制安装、卸载、启动、停止,以及查看状态
  3. 支持控制台调试应用,解决Windows服务难以调试的问题
  4. 支持健康检测,限制内存、线程数、句柄数,超限时重启应用服务
  5. 支持应用服务定时重启,通过配置指定
  6. 支持看门狗WatchDog,通过配置指定要守护的目标应用服务,如果目标停止则启动
  7. 支持配置文件修改服务名,一个应用程序可在多个目录上部署为不同的系统服务

服务控制

一个服务代理示例跑起来的样子
image.png
image.png
这是Agent的标准控制台(Windows和Centos)。上面是该服务的状态信息,下面是控制菜单。
示例分析:

  • 服务名 XAgent/StarAgent,可以命令启动停止,Windows是net start XAgent/net stop XAgent,Linux是systemctl start StarAgent/systemctl stop StarAgent
  • 显示名“新生命服务代理”是在windows服务控制板里面看到的名字
  • 下一段信息给出了DH.NAgent和当前应用的版本信息和编译时间
  • 黄色菜单可通过按键选择相应操作,内置012345,可自定义其它按键操作
  • 菜单1,显示状态,按下1后刷新状态信息
  • 菜单2,安装服务或卸载服务,安装成功后,显示信息变为卸载服务,反之亦然
  • 菜单3,启动服务或停止服务,安装后才可以看见
  • 菜单4,重启服务,安装且运行后可以看见
  • 菜单5,模拟运行,在当前进程启动应用主逻辑,用于业务逻辑调试,等同于Windows服务调用
  • 菜单0,退出应用服务

!!!注意,服务安装、卸载、启动、停止,在Windows/Linux上需要管理员权限运行

服务应用在Windows上以本地用户权限运行,有最高权限;
服务应用在Linux上以root权限运行,有最高权限;
该设计尽管带来了一定安全风险,但能够避免绝大部分初级用户的简单问题,优先易用性。


多种守护体系实现

下面列出各平台对应的守护实现及其行为特征,便于按需选择或排障:

  • WindowsService(Windows 服务)

    • 通过 Win32 服务控制管理器(SCM)注册和运行,内部使用 StartServiceCtrlDispatcher/RegisterServiceCtrlHandlerEx 等 API。
    • 支持电源事件、会话变更、时间变更等系统事件回调;安装时自动配置“失败重启”动作。
    • 安装/启停:需要管理员;对应命令 sc/net start|stop。适合服务器长期托管。
  • WindowsAutorun(Windows 登录自启动)

    • 将应用写入注册表 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run,随登录自动启动。
    • 使用 .pid 文件跟踪进程并实现停止;更适合桌面/开发环境或需要交互桌面的场景。
    • 安装/卸载:写入 HKLM 需管理员;启停不依赖 SCM。
  • Systemd(Linux systemd)

    • 生成 <ServiceName>.service 单元文件到常见目录(优先于 /etc/systemd/system 等),并执行 daemon-reload/enable
    • 支持设置 WorkingDirectoryExecStartUser/Group 等;启动/停止/重启通过 systemctl 执行。
    • 适用大多数现代 Linux 发行版,是 Linux 优先选择的托管方式。
  • RcInit(Linux SysV init 兼容)

    • 生成 ServiceName.sh 控制脚本(当前应用目录),并在 /etc/rc*.d//etc/rc.d/ 创建 S50/K50 级别的软链接。
    • sh ServiceName.sh start|stop|restart 方式管理;用 .pid 文件跟踪进程。
    • 适合仍使用 SysV init 或 BusyBox 的传统/裁剪系统。
  • Procd(OpenWrt 专用)

    • 运行时探测 PID 1 是否为 procd 判定环境;生成 ServiceName.sh 并在 /etc/rc.d/ 创建 S50 链接。
    • nohup 启动,.pid 文件跟踪,kill 停止;贴合 OpenWrt 生态的守护方式。
  • OSXLaunch(macOS launchd)

    • ~/Library/LaunchAgents/ 写入 ServiceName.plist,设定 ProgramArgumentsRunAtLoad,通过 launchctl 管理。
    • 适合用户级代理(LaunchAgents);如需系统级可按需调整到 LaunchDaemons。
  • DefaultHost(默认主机)

    • 无平台集成能力,仅作为兜底执行 Run/Stop 循环;通常只有在无法检测到任何平台守护体系时才会落到此实现。

WatchDog 在 Systemd 主机中守护其它服务时,会智能探测被守护服务实际托管方式(Systemd/SysV),避免“已安装但未检测到”的误判。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

  • .NETFramework 4.6.1

  • .NETStandard 2.0

  • .NETStandard 2.1

  • net10.0

  • net6.0

  • net7.0

  • net8.0

  • net9.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DH.NAgent:

Package Downloads
DH.Extensions.Hosting.AgentService

为ASP.NET Core与Worker提供Agent托管集成,支持服务化部署与运维。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.21.2026.412-beta0537 135 4/12/2026
4.21.2026.326-beta0752 149 3/26/2026
4.21.2026.305-beta0046 155 3/5/2026
4.21.2026.304-beta0026 144 3/4/2026
4.18.2026.301-beta0228 135 3/1/2026
4.18.2026.225-beta0320 151 2/25/2026
4.18.2026.210 208 2/10/2026
4.18.2026.210-beta0554 144 2/10/2026
4.17.2026.130-beta0201 158 1/30/2026
4.17.2026.114-beta0410 149 1/14/2026
4.17.2026.112-beta1143 244 1/12/2026
4.17.2026.106-beta1013 149 1/6/2026
4.16.2025.1113 476 11/13/2025
4.16.2025.1113-beta0615 345 11/13/2025
4.16.2025.1113-beta0614 334 11/13/2025
4.15.2025.1024-beta1307 178 10/24/2025
4.15.2025.1024-beta1302 173 10/24/2025
4.15.2025.1002-beta0310 216 10/2/2025
4.15.2025.1002-beta0309 208 10/2/2025
4.13.2025.926-beta1153 189 9/26/2025
Loading failed

新增Desktop,支持Windows后台服务在用户会话打开应用;重构菜单架构;增强Systemd支持更多参数设置