How do I compile my App.config into my exe in a VS2010 C# console app?

Patches picture Patches · Jan 3, 2011 · Viewed 44.1k times · Source

I'm creating a console app in Visual Studio 2010 with c#. I want this app to be stand alone, in that all you need is the exe, and you can run it from anywhere. I also want to use app.config to store connection strings and so on.

My problem is that I can't seem to figure out how to include that app.config data into the compiled exe. I do see it creates appname.exe.config, but I don't want people to have to worry about grabbing two separate files when they get the app.

None of the googling I've done has come up with anything. Is this even possible?

Answer

Billy ONeal picture Billy ONeal · Jan 3, 2011

You can't. Half the point of such config files is to allow changes to the configuration of the app outside of the app itself.

You would simply have to modify your program so that it didn't have a dependency on the app config file -- easiest way to do that would be to just stick the values inside your config into read only global variables.