Common.Config 1.0.6

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

⚙️ Common.Config

A shared configuration library for desktop apps that supports per-application settings, ClickOnce-safe storage, and default config seeding from embedded JSON.


✅ Features

✔ Per-app configuration using %AppData%
✔ Strongly typed config class support
✔ Multi-class support in a single config file
✔ Loads defaults from embedded .defaults.json
✔ Safe across ClickOnce updates
✔ Uses System.Text.Json
✔ Fully DI-compatible with generic AppSettingsService<T>


📦 Installation

Install via your internal NuGet feed:

dotnet add package Common.Config --version 1.0.x

✅ Usage in Code

1. Register Config Service in Startup

// Register multiple classes if needed:
services.AddAppSettings<RefboxConfig>("RefboxManager", key: "RefboxConfig");
services.AddAppSettings<NetworkOptions>("RefboxManager", key: "NetworkOptions");

🧠 The softwareName controls the config path at:

%AppData%\OptonMedia\<SoftwareName>\settings.json

2. Define Your Settings Models

public class RefboxConfig
{
    public string ReferenceBoxName { get; set; }
    public int RetryAttempts { get; set; }
}

public class NetworkOptions
{
    public string Hostname { get; set; }
    public int Port { get; set; }
}

3. Inject and Use Them

public class MyViewModel
{
    private readonly AppSettingsService<RefboxConfig> _refboxSettings;

    public MyViewModel(AppSettingsService<RefboxConfig> refboxSettings)
    {
        _refboxSettings = refboxSettings;
    }

    public void Update()
    {
        _refboxSettings.Settings.ReferenceBoxName = "WD999";
        _refboxSettings.Save();
    }
}

🧾 Example Embedded Default Config

File: RefboxManager.defaults.json (Build Action: Embedded Resource)

{
  "RefboxConfig": {
    "ReferenceBoxName": "WD191",
    "RetryAttempts": 3
  },
  "NetworkOptions": {
    "Hostname": "localhost",
    "Port": 8080
  }
}

📂 Config File Locations

Purpose Location
Default config Embedded as <SoftwareName>.defaults.json in your app
Runtime settings %AppData%\OptonMedia\<SoftwareName>\settings.json

🧠 Behavior

  • On first launch:
    • If no config file exists, loads defaults from embedded .defaults.json
    • Then saves them to %AppData%
  • On future launches:
    • Always reads updated values from %AppData%

✅ Good Practices

  • Do not hardcode defaults in your model classes
  • Do not manually modify %AppData% JSON files
  • Each app must pass a unique softwareName to AddAppSettings<T>
  • Always call Save() to persist changes

🚫 Limitations

  • JSON comments (//, /* */) are not supported
  • No built-in schema validation

📌 Example Apps

  • RefboxManager
  • HPWLSBurnInTest
  • WeldMasterConfigTool

Each uses this shared NuGet package with its own .defaults.json and config model.


📦 Folder Structure

/Common.Config
    /IAppSettingsProvider.cs
    /JsonAppSettingsProvider.cs
    /AppSettingsService.cs
    /ConfigServiceExtensions.cs

✅ Future Features

  • 🔐 Encrypted fields for secrets
  • 🧪 Config validation helpers
  • 💾 Backup/restore APIs
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.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 was computed. 
.NET Framework net461 was computed.  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.

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.6 175 8/8/2025