0

For a C# .NET 4.5 application in Visual Studio 2012 (or any .NET and VS version), when is Settings.cs created or first referenced?

I use Settings.cs to retrieve some user preferences on program startup and to store them when the program exits. I once forgot to put Settings.cs under version control and when a user grabbed my branch and ran the .exe from bin\debug or \release he got a popup error message related to the missing file that didn't come back the second time he ran the program.

Is Settings.cs even automatically created or must it be provided with the solution? If so, can it be generated with code?

valsidalv
  • 761
  • 2
  • 19
  • 33
  • Are you actually reading the `.cs` file from your code at run time? – p.s.w.g Nov 12 '13 at 17:19
  • @p.s.w.g Good point. No, I'm just looking at the variables within Settings.settings (or Properties.Settings.Default through the code). – valsidalv Nov 12 '13 at 17:21
  • 1
    Why not use app.config? – Andrew Cooper Nov 12 '13 at 17:21
  • 1
    @AndrewCooper, because app.config isn't designed to store user settings, since it can't be modified by the process that uses it (at least not easily). Settings.settings, OTOH, exists precisely for this purpose. – Thomas Levesque Nov 12 '13 at 17:23
  • @AndrewCooper "Adding a .settings to your project will result in an app.config being added to house the settings if you dont already have one" http://stackoverflow.com/questions/909688/what-is-the-difference-between-app-config-file-and-xyz-settings-file – valsidalv Nov 12 '13 at 17:29
  • Cool. I learned something new. Thanks. – Andrew Cooper Nov 12 '13 at 17:34

1 Answers1

2

It is created (or re-created) automatically whenever you save the Settings.settings file (which happens, for instance, when you edit the settings via the project's property pages)

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758