Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 309
Patches Avatar asked Jan 03 '11 16:01

Patches


People also ask

How do I create an exe for console application?

First, right-click on the project and then hit Publish, then select folder and click create. Click the edit button to edit the configuration. In the publish configuration you can check the single EXE option. Once ready, save and click Publish.

Does app config get compiled?

Now you might be wondering what happens behind the scenes. Well, when you compile your application, the compiler actually copies the app. config file to the output folder, but gives it another name: When you start your application (ConsoleApp1.exe in our example), the matching config file will be loaded too.

What is exe config file in C#?

Config is the file used in your development environment. AppName.exe. config is the app. config file used when your app is deployed.

Does app config get compiled into DLL?

If you don't want to expose values, make sure you have an app. config with deployment values (empty, 0, or something). The values WILL be compiled into the DLL as default values.


1 Answers

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.

like image 58
Billy ONeal Avatar answered Sep 19 '22 05:09

Billy ONeal