Jeroen
Jeroen

Reputation: 460

Where does a console application REALLY store its settings

I've created a console app (VS2015, target framework 4.5.2) and I have used My Project/Settings to create application level settings. All the documentation and answers here on stackoverflow.com tell me (and this is the way I've always understood it to work) that the app.config file are where these things are stored and I can indeed see these settings in app.config and I can open settings.vb to look at the properties and their default values.

So far so good, when I compiled this and chucked ONLY the executable on a different machine, as expected it worked. I am assuming this is because settings.vb is compiled into the app.

But I am left with an application for which I can't change the settings. Where do I now put the app.config so that I can indeed change the settings in the XML and have my application use those settings instead of the default ones next time? I hope I don't have to build an installer or do a publish because to me that completely defeats the purpose of console applications.

Upvotes: 1

Views: 260

Answers (1)

egray
egray

Reputation: 390

By default the settings in app.config are also embedded into your code (just for those situations like what you describe... where you just have the EXE without any *.config file). You can change this behavior by changing the GenerateDefaultValueInCode for each setting.

There are two sections to the file... the application section has the read-only setting for the entire app. The user section has the starting default values of the settings that the user can change.

So, just to review:

  • app.config = the design-time version of all the settings (it gets renamed and copied to bin)
  • YourApplication.exe.config = the run-time version of the all of the settings
  • %LOCALAPPDATA%\App\Version\user.config = just the user portion of the settings after they've made changes

Upvotes: 3

Related Questions