https://github.com/bluegrams/settingsproviders
PortableSettingsProvider and PortableJsonSettingsProvider for .NET
https://github.com/bluegrams/settingsproviders
csharp dotnet json portable settings settings-portable winforms wpf
Last synced: 3 months ago
JSON representation
PortableSettingsProvider and PortableJsonSettingsProvider for .NET
- Host: GitHub
- URL: https://github.com/bluegrams/settingsproviders
- Owner: Bluegrams
- License: bsd-3-clause
- Created: 2019-01-05T14:23:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-01T21:41:16.000Z (almost 2 years ago)
- Last Synced: 2025-03-06T10:55:46.336Z (4 months ago)
- Topics: csharp, dotnet, json, portable, settings, settings-portable, winforms, wpf
- Language: C#
- Homepage: https://www.codeproject.com/Articles/1238550/Making-Application-Settings-Portable
- Size: 27.3 KB
- Stars: 44
- Watchers: 6
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SettingsProviders
This repository provides two custom implementations of the `SettingsProvider` class in the .NET Framework application settings architecture.
They can be used to make the built-in application of WinForms and WPF application settings portable and more configurable:* **PortableSettingsProvider** saves app settings in an XML format similar to the built-in settings provider
* **PortableJsonSettingsProvider** saves app settings in JSON format, powered by Newtonsoft.Json### Features
* Make application settings portable together with the app
* Configure the location and name of the settings file
* Easily plug into existing apps (just one line needed to make existing app settings portable)## Usage
_Note:_ Change all occurrences of `PortableSettingsProvider` to `PortableJsonSettingsProvider` to use the JSON version.
1. Install the nuget package:
[`Install-Package PortableSettingsProvider`](https://www.nuget.org/packages/PortableSettingsProvider) or
[`Install-Package PortableJsonSettingsProvider`](https://www.nuget.org/packages/PortableJsonSettingsProvider)
2. Apply the provider to your settings:
```
PortableSettingsProvider.ApplyProvider(Properties.Settings.Default);
```
Make sure to adjust the name of the settings instance if it is not the default settings.
For an alternative approach, see [here](https://www.codeproject.com/Articles/1238550/Making-Application-Settings-Portable).
3. Optionally, you can set a different name and location for the settings file.
A full configuration for a WinForms application might look like this:
```csharp
static void Main()
{
PortableSettingsProvider.SettingsFileName = "settings.config";
PortableSettingsProvider.SettingsDirectory = "Some\\custom\\location";
PortableSettingsProvider.ApplyProvider(Properties.Settings.Default);
Application.Run(new Form1());
}
```## More
For a detailed explanation of the implementation and more options,
visit the [related CodeProject article](https://www.codeproject.com/Articles/1238550/Making-Application-Settings-Portable).
The article also explains the difference between _roamed_ and _local_ settings as the settings providers support both.## License
[BSD-3-Clause](LICENSE) License.