GotifyOnLine 1.0.0

dotnet add package GotifyOnLine --version 1.0.0
                    
NuGet\Install-Package GotifyOnLine -Version 1.0.0
                    
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="GotifyOnLine" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GotifyOnLine" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GotifyOnLine" />
                    
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 GotifyOnLine --version 1.0.0
                    
#r "nuget: GotifyOnLine, 1.0.0"
                    
#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 GotifyOnLine@1.0.0
                    
#: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=GotifyOnLine&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GotifyOnLine&version=1.0.0
                    
Install as a Cake Tool

GotifyOnLine

引用即用的 Gotify 消息推送 NuGet 包。

特性

  • 引用后自动注册 GotifyService 与启动通知 HostedService
  • 应用启动后自动发送一条 Gotify 启动通知
  • 失败只记录日志,不抛出异常,不影响应用启动

使用方式

ASP.NET Core(自动注册)

  1. 安装 NuGet 包 GotifyOnLine
  2. 在 appsettings.json 中配置:
{
  "Gotify": {
    "Enabled": true,
    "ApiBase": "http://192.168.0.75:40266",
    "AppToken": "your-app-token",
    "Priority": 5,
    "SendStartupNotification": true,
    "StartupTitleTemplate": "[启动成功] {ApplicationName}",
    "StartupMessageTemplate": "机器:{MachineName}\r\n环境:{EnvironmentName}\r\n时间:{Now}"
  }
}
  1. 运行应用,启动后会自动收到 Gotify 通知。

非 Web 项目或需要显式注册

builder.Services.AddGotify(builder.Configuration);

手动发送消息

public class MyService
{
    private readonly GotifyService _gotify;

    public MyService(GotifyService gotify)
    {
        _gotify = gotify;
    }

    public async Task NotifyAsync()
    {
        await _gotify.SendAsync("标题", "内容", priority: 8);
    }
}

模板占位符

启动通知标题与内容模板支持以下占位符:

  • {ApplicationName}
  • {EnvironmentName}
  • {MachineName}
  • {Now}(格式化为 yyyy-MM-dd HH:mm:ss)

发布到 NuGet

仓库已配置 GitHub Actions 工作流 .github/workflows/publish-nuget.yml,采用 NuGet 可信发布(Trusted Publishing),无需长期 API 密钥。

  • 推送 main/master 分支:仅构建并打包,不发布。
  • 推送标签 v*.*.*:自动打包并以标签版本发布到 NuGet.org。

配置可信发布

  1. 登录 nuget.org,点击用户名 → 受信任的发布。
  2. 新增策略:
    • 存储库所有者:你的 GitHub 用户名/组织名
    • 存储库:GotifyOnLine
    • 工作流文件:publish-nuget.yml
    • 环境(可选):release
  3. 在 GitHub 仓库 Settings → Secrets and variables → Actions 中添加 NUGET_USER(nuget.org 个人资料名,非邮箱)。

发布示例

git tag -a v1.0.1 -m "release v1.0.1"
git push origin v1.0.1
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 130 7/29/2026