Home > Enterprise >  Where are the default values in .settings files stored for .NET 6 WPF apps?
Where are the default values in .settings files stored for .NET 6 WPF apps?

Time:01-22

I have a .NET 6 WPF desktop app that uses several .settings files for managing user settings but the user can't manage the settings because I don't know where the default values are stored.

If I change a value in code at runtime:

FontSettings.FontFamily=someFont;
FontSettings.Save();

only then do I get a settings file generated in C:\Users\{UserName}\AppData\Local\{AppName}\{Version}\blaBla.config, but even then, it only writes the value that I manually changed in code so I have to guess what are the names of the other values.

If I don't change any value in code, the file just isn't being generated. How is a user supposed to change the default values? Decompile the app?

Some other questions that you might think are duplicates suggest that these settings are in an appConfig.config file or other some such. I don't know what .net version they're using but I don't have such a file in my project.

CodePudding user response:

When you add a settings file and set a value on a setting in it, you should also find an app.config is added in the root of your project.

When I try that in a solution I have I see these files in git changes

enter image description here

I did not add app.config myself but it only appeared when I added settings1 and then saved a setting in it.

Mine looks like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="XXXXXXX.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <XXXXX.Settings1>
            <setting name="fooo" serializeAs="String">
                <value>bar</value>
            </setting>
        </XXXXX.Settings1>
    </userSettings>
</configuration>
  • Related