1

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.

Jeroen
  • 460
  • 6
  • 14
  • I don't know what you can do with the `app.config`, I think you can ship it with your application, but the first time you start an application on a computer a settings file will be generated in a location looking something like this: `%LocalAppData%\[Your Company Name]\[Your App Name And Version with other random letters]`. – Visual Vincent Jul 13 '16 at 22:56
  • I am not seeing that location... – Jeroen Jul 13 '16 at 23:05
  • Closest I get is: `C:\Users\myusernamehere\AppData\Local` – Jeroen Jul 13 '16 at 23:21
  • And you see no folder containing your app's file name/company name? – Visual Vincent Jul 13 '16 at 23:34
  • No I sure don't :-( – Jeroen Jul 13 '16 at 23:35
  • Hmm, that's strange... I'll see if I can dig something up tomorrow. In the meantime [**this answer**](http://stackoverflow.com/a/17245548/3740093) explains what I am talking about. – Visual Vincent Jul 13 '16 at 23:38
  • It is indeed a bit strange I read that one too... Thanks for all the help! – Jeroen Jul 13 '16 at 23:41

1 Answers1

3

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
SSS
  • 4,807
  • 1
  • 23
  • 44
egray
  • 390
  • 1
  • 4
  • One thing to note... The application targets framework 4.5.2. On the destination machine this version is NOT available. When I copy JUST the executable, it gracefully dumbs down to a lower version. When I add the `myapplication.exe.config` it stops functioning and asks me to install version 4.5.2. When you edit the `config` file all is well again. Just something to look out for. – Jeroen Jul 15 '16 at 02:14