Search code examples
c#wpf.net-6.0.net-5.net-7.0

Equivalent to UserSettings / ApplicationSettings in WPF for newer .NET versions


What is the prefered way for persisting user settings for WPF applications with , , or >=3.0?
Where are the .NET user settings gone?

Created WPF .Net Core 3.0 Project (VS2019 V16.3.1)
Now I have seen there is no Properties.Settings section anymore.

[Update 2022: With .NET 6 it is still the same]
[Update 2023: With .NET 7 it is still the same]

SolutionExplorer

After online search, started to dive into Microsoft.Extensions.Configuration.

Beside the bloated code to access the settings, now even worse -> No save?
User Configuration Settings in .NET Core

Fortunately or unfortunately the Microsoft.Extensions.Configuration does not support saving by design. Read more in this Github issue Why there is no save in ConfigurationProvider?


What is the prefered (and easy/fast/simple) way for persisting user settings for WPF applications with .Net Core >=3.0 / .NET5 / .NET6 / .NET7?
Before <= .Net 4.8 it was as easy as:
  • add the variables to the Properties. User Settings

  • Read the variables at startup
    var culture = new CultureInfo(Properties.Settings.Default.LanguageSettings);

  • when a variable changes -> immediately save it
    Properties.Settings.Default.LanguageSettings = selected.TwoLetterISOLanguageName; Properties.Settings.Default.Save();


Solution

  • enter image description here

    You can add the same old good settings file e.g. via the right click on the Properties -> Add -> New Item and search for the "Settings". The file can be edited in the settings designer and used as in the .net framework projects before (ConfigurationManager, Settings.Default.Upgrade(), Settings.Default.Save, etc. works).

    Add also the app.config file to the project root folder (the same way via the Add -> New Item), save the settings once again, compile the project and you will find a .dll.config file in the output folder. You can change now default app values as before.

    Tested with Visual Studio 1.16.3.5 and a .net core 3.0 WPF project.