Abraham.ProgramSettingsManager 1.0.4

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

Abraham.ProgramSettingsManager

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image GitHub Repo stars GitHub Repo stars

OVERVIEW

Enables you to use a JSON file for configuration of your app (typically appsettings.hjson or appsettings.json).

License

Licensed under Apache licence. https://www.apache.org/licenses/LICENSE-2.0

Compatibility

The nuget package was build with DotNET 6.

INSTALLATION

Install the Nuget package "Abraham.ProgramSettingsManager" into you application (from https://www.nuget.org).

Add the following code:

private static ProgramSettingsManager<Configuration> _myConfiguration;

static void Main(string[] args)
{
    // easy version:
    _myConfiguration = new ProgramSettingsManager<Configuration>().Load();
    Console.WriteLine($"A value from my appsettings.hjson file: {_myConfiguration.Data.Option1}");

. . . your code
}

class Configuration
{
    public string Option1 { get; set; }
    public string Option2 { get; set; }
    public string Option3 { get; set; }
}

Add a file named "appsettings.hjson" to your project, make sure it's copied to the output directory (bin directory) of your app, with this content:

{
    Option1: "my value 1",
    Option2: "my value 2",
    Option3: "my value 3",
}

That's it!

For more options, please refer to my Demo application in the github repository (see below). The Demo and the nuget source code is well documented.

USING SPECIAL FOLDERS FOR YOUR PROGRAM SETTINGS

You can use method 'UsePathRelativeToSpecialFolder' to set a certain path and filename, relative to a known folder.

    _myConfiguration = new ProgramSettingsManager<Configuration>()
        .UsePathRelativeToSpecialFolder(@"%APPLICATIONDATA%\AcmeCompany\Appsettings.json")
        .Load();

More possibilities are:

  • %APPLICATIONDATA%\AcmeCompany\Appsettings.json
  • %LOCALAPPLICATIONDATA%\AcmeCompany\Appsettings.json
  • %COMMONDOCUMENTS%\MyProgram\Appsettings.json
  • %MYDOCUMENTS%\MyProgram\Appsettings.json
  • %TEMP%\MyProgram\Appsettings.json

Create a default configuration if the file is missing

You can use method 'CreateIfMissing' before Load to create an empty default instance, if the configuration file doesn't exist yet.

    _myConfiguration = new ProgramSettingsManager<Configuration>()
        .CreateIfMissing()
        .Load();

HOW TO INSTALL A NUGET PACKAGE

This is very simple:

  • Start Visual Studio (with NuGet installed)
  • Right-click on your project's References and choose "Manage NuGet Packages..."
  • Choose Online category from the left
  • Enter the name of the nuget package to the top right search and hit enter
  • Choose your package from search results and hit install
  • Done!

or from NuGet Command-Line:

Install-Package Abraham.ProgramSettingsManager

AUTHOR

Oliver Abraham, mail@oliver-abraham.de, https://www.oliver-abraham.de

Please feel free to comment and suggest improvements!

SOURCE CODE

The source code is hosted at:

https://github.com/OliverAbraham/Abraham.ProgramSettingsManager

The Nuget Package is hosted at:

https://www.nuget.org/packages/Abraham.ProgramSettingsManager

SCREENSHOTS

Main screen of the demo: alternate text is missing from this package README image

MAKE A DONATION !

If you find this application useful, buy me a coffee! I would appreciate a small donation on https://www.buymeacoffee.com/oliverabraham

<a href="https://www.buymeacoffee.com/app/oliverabraham" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Abraham.ProgramSettingsManager:

Package Downloads
Abraham.HomenetFramework

Bundle of MQTT client, Program settings reader, Program state reader/writer, background worker, NLog logger. Useful to build HomeAssistant clients for Linux and Windows (also WPF).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 427 4/4/2024
1.0.2 823 10/7/2022
1.0.1 738 8/18/2022
1.0.0 756 6/12/2022

Fixed bug in "UseFilename" method