How to properly set a settings.settings file properties for a windows setup project in visual studio

2025-12-15T14:29:59.4166667+00:00

I have a C# windows forms application that i am trying to make a setup project for. The application gives no errors and i have successfully deployed it with a setup project (msi file) however, i have a settings.settings file in the project to allow for the user to customize their program (colors, save folder, etc). Currently the settings file is not either, deployed correctly or is not updating to the users settings because it does not keep any of their settings for the next time the use the app. I have used these in the past with visual basic forms programs and had no problems. This is the first time i have used them in a C# win forms application. I had to create the settings file so i am assuming i have a properties setting not set right for deployment. i am currently using Properties.Settings.Default.Save(); when the user updates things, but no luck so far. Appreciate any help or suggestions.

Windows development | Windows App SDK
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Raymond Huynh (WICLOUD CORPORATION) 3,955 Reputation points Microsoft External Staff Moderator
    2025-12-16T09:03:32.9266667+00:00

    Hello Friedrich von Frederick of Fredericksburg,

    Thanks for the context. The reason your settings aren’t “sticking” isn’t because of some missing MSI property, it’s because of how .NET application settings actually work, and that behavior is the same in C# as in VB.

    In Windows Forms, the .settings file you see in the project is just a design-time definition of settings. At runtime, when you call:

    Properties.Settings.Default.Save();
    

    only user-scoped settings are persisted, and they are not saved into the MSI or your installation folder at all. They are written by the .NET runtime into a per-user configuration file in the user’s profile (not in the install directory). This is documented behavior.

    So two key points:

    1. Scope matters Make sure in the Settings designer that the settings you expect to change have Scope = User. If they are Application scope, calling .Save() doesn’t persist anything because application-scoped settings are read-only at runtime.
    2. MSI installers don’t deploy the user config An MSI will install your application binaries and any default app.config (which holds defaults), but the actual saved values for user settings are written at runtime into a separate config file under the user’s profile. There is no MSI property to “deploy user settings”.

    That explains why you saw this work in VB before: in VB, the settings system automatically saves user settings when the app closes (via My.Settings), whereas in C# you must explicitly call Properties.Settings.Default.Save() after the user changes values.

    If you want to verify if the values are being saved at all, you can retrieve the actual file path the runtime uses and inspect it at runtime:

    var cfg = System.Configuration.ConfigurationManager
        .OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal);
    MessageBox.Show(cfg.FilePath);
    

    That will show you the exact per-user config file being used. If the values aren’t there after you save, then either the scope is wrong or the save call isn’t being reached.

     

    Hope this helps!

    1 person found this answer helpful.
    0 comments No comments

  2. Q&A Assist
    2025-12-15T14:30:53.38+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To properly set up a settings.settings file in your C# Windows Forms application for deployment, ensure the following steps are followed:

    1. Create the Settings File: In Visual Studio, create a Settings.settings file if you haven't already. This file should be located in the Properties folder of your project.
    2. Define Settings in the Settings Designer: Open the Settings.settings file in the Settings designer. Here, you can define your settings, including their name, type, scope (User or Application), and default value. Make sure to set the scope to User for settings that need to be user-specific (like colors, save folder, etc.).
    3. Accessing and Saving Settings: Use Properties.Settings.Default to access your settings in code. When the user updates any settings, call Properties.Settings.Default.Save(); to persist those changes. This should be done after the user modifies any settings.
    4. Deployment Considerations: When deploying your application, ensure that the user.config file is correctly created and accessible. In a ClickOnce deployment, the user.config file is stored in the ClickOnce data directory. If you are using a standard MSI setup, the user.config file will be created in the user's profile directory (usually under Documents and Settings or Users).
    5. Check for Errors: If the settings are still not saving, check for any exceptions that might occur during the save process. Ensure that the application has the necessary permissions to write to the user's profile directory.

    By following these steps, your application should correctly save and load user-specific settings upon subsequent launches.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.