BugFree.Configuration
1.2.2026.615-beta1053
This is a prerelease version of BugFree.Configuration.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BugFree.Configuration --version 1.2.2026.615-beta1053
NuGet\Install-Package BugFree.Configuration -Version 1.2.2026.615-beta1053
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="BugFree.Configuration" Version="1.2.2026.615-beta1053" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BugFree.Configuration" Version="1.2.2026.615-beta1053" />
<PackageReference Include="BugFree.Configuration" />
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 BugFree.Configuration --version 1.2.2026.615-beta1053
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BugFree.Configuration, 1.2.2026.615-beta1053"
#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 BugFree.Configuration@1.2.2026.615-beta1053
#: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=BugFree.Configuration&version=1.2.2026.615-beta1053&prerelease
#tool nuget:?package=BugFree.Configuration&version=1.2.2026.615-beta1053&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
BugFree.Configuration
BugFree.Configuration 是一个轻量级、强类型的 .NET 配置管理框架,支持 INI / XML / JSON / YAML 四种序列化格式,提供可选加密(AES-GCM)、原子写入保存和文件监视/定时轮询热重载能力。
✨ 特性
- 🔧 强类型配置 — 继承
Config<T>即可获得统一的加载/保存/热重载 API,无需手写样板代码 - 📄 多格式支持 — 内置 INI、XML、JSON、YAML 四种序列化器,通过
[Config]特性声明即可切换 - 🔒 可选加密 — 基于 AES-GCM 的对称加密,依赖
BugFree.Security,密钥自动管理 - ⚡ 原子写入 — 保存时先写临时文件再
Move覆盖,避免写半损坏 - 🔄 热重载 — 支持
FileWatcher(文件系统监视)与Timer(定时轮询)两种模式 - 🛡️ 文件占用重试 — 读写时自动重试,兼容编辑器保存和部署原子替换场景
📦 安装
dotnet add package BugFree.Configuration
🚀 快速入门
1. 定义配置模型
using BugFree.Configuration;
using BugFree.Serialization;
[Config(Name = "app", Type = SerializationType.Json, Path = "./config")]
public class AppConfig : Config<AppConfig>
{
public string Name { get; set; } = "MyApp";
public int Port { get; set; } = 8080;
}
2. 读取配置
var config = AppConfig.Current;
Console.WriteLine(config.Name); // MyApp
3. 修改并保存
var config = AppConfig.Current;
config.Port = 9090;
config.Save(); // 原子写入到 ./config/app.json
4. 监听变更
AppConfig.Changed += (sender, args) =>
{
Console.WriteLine($"配置已变更(来源:{args.ChangeSource})");
};
AppConfig.ReloadFailed += (sender, args) =>
{
Console.WriteLine($"重载失败:{args.Exception.Message}");
};
⚙️ 配置选项
通过 [Config] 特性声明配置行为:
| 属性 | 说明 | 默认值 |
|---|---|---|
Type |
序列化格式:Json / Xml / Yaml / Ini |
Json |
Path |
配置文件存放目录 | ./config |
Name |
文件名主体(不含扩展名) | 配置类型名 |
Reloader |
热重载方式:FileWatcher / Timer |
FileWatcher |
EnableEncryption |
是否启用 AES-GCM 加密 | false |
KeyName |
加密密钥名称 | ConfigSymmetricKey |
🧩 项目依赖
- BugFree.Serialization — 文本序列化(INI/XML/JSON/YAML)
- BugFree.Security — 对称加密(AES-GCM)(可选)
🏗️ 软件架构
Config<T> ← 强类型配置基类(入口)
├── ConfigAttribute ← 声明式元数据(格式、路径、加密、重载)
├── ConfigProvider ← 配置读写提供者(文件解析、加解密、原子写入)
│ ├── ConfigCryptoService ← 加解密服务(AES-GCM)
│ └── ConfigLoadContext ← 运行时上下文(路径、格式、加密参数)
└── HotReloader/
├── HotReloaderBase ← 热重载基类(抑制窗口、写入基线)
├── FileWatcherReloader ← 文件系统监视重载
└── TimerReloader ← 定时轮询重载
📋 环境要求
- .NET 8.0 或 .NET 10.0+
- Windows / Linux / macOS
🤝 参与贡献
- Fork 本仓库
- 新建特性分支
Feat_xxx - 提交代码
- 发起 Pull Request
📄 许可证
本项目基于 MIT 许可证开源。
| Product | Versions 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- BugFree.Security (>= 1.2.2026.614-beta1531)
- BugFree.Serialization (>= 1.2.2026.615-beta1047)
-
net8.0
- BugFree.Security (>= 1.2.2026.614-beta1531)
- BugFree.Serialization (>= 1.2.2026.615-beta1047)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on BugFree.Configuration:
| Package | Downloads |
|---|---|
|
BugFree.FileStorage
Package Description |
|
|
BugFree.XCode.Extensions
NewLife.XCode ORM 扩展库,提供 BugFree 实体基类、数据模型接口、数据库连接及配置集成。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.2026.616-beta0953 | 120 | 6/16/2026 |
| 1.2.2026.615-beta1053 | 100 | 6/15/2026 |
| 1.2.2026.614-beta1936 | 95 | 6/14/2026 |
| 1.2.2026.613-beta1556 | 101 | 6/13/2026 |
| 1.1.2026.121-beta1102 | 151 | 1/21/2026 |
| 1.1.2026.115-beta1530 | 139 | 1/15/2026 |
| 1.0.250901.1420 | 274 | 9/1/2025 |
| 1.0.250817.1009 | 198 | 8/17/2025 |
| 1.0.250817.1003 | 197 | 8/17/2025 |
| 1.0.250817.955-beta0955 | 190 | 8/17/2025 |
| 1.0.2026.115-beta1414 | 120 | 1/15/2026 |
| 1.0.2026.106-beta1135 | 136 | 1/6/2026 |
| 1.0.2025.1224-beta1648 | 218 | 12/24/2025 |
| 1.0.2025.1224-beta1406 | 219 | 12/24/2025 |
| 1.0.2025.1224-beta1342 | 208 | 12/24/2025 |
支持 Ini/Xml/Json/Yaml 多格式配置;可选 AES-GCM 加密存储;原子写入保存;统一强类型 API(Config<T>.Current/Save);文件热重载。