Abraham.ProgramSettingsManager
1.0.2
See the version list below for details.
dotnet add package Abraham.ProgramSettingsManager --version 1.0.2
NuGet\Install-Package Abraham.ProgramSettingsManager -Version 1.0.2
<PackageReference Include="Abraham.ProgramSettingsManager" Version="1.0.2" />
<PackageVersion Include="Abraham.ProgramSettingsManager" Version="1.0.2" />
<PackageReference Include="Abraham.ProgramSettingsManager" />
paket add Abraham.ProgramSettingsManager --version 1.0.2
#r "nuget: Abraham.ProgramSettingsManager, 1.0.2"
#:package Abraham.ProgramSettingsManager@1.0.2
#addin nuget:?package=Abraham.ProgramSettingsManager&version=1.0.2
#tool nuget:?package=Abraham.ProgramSettingsManager&version=1.0.2
Abraham.ProgramSettingsManager
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
| Product | Versions 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. |
-
net6.0
- Hjson (>= 3.0.0)
- Newtonsoft.Json (>= 13.0.1)
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.