Take the 2-minute tour ×

When you compile a C# project, the app settings from app.config are saved along with the exe file. For example, if the program name is "solve_np.exe", there will be a "solve_np.exe.config" next to it, making it look less neat than I want it to. How can you embed it into the .exe?

I tried to set Build Action to Embed Resource, but that did not do the trick.

share|improve this question
add comment

7 Answers

up vote 10 down vote accepted

Aha. I guess you're falling foul of Visual Studio automatically placing stuff in configuration that you DONT want configured by the end user.

In this case use resources. Simply add a new file of type .resx. With this you'll be able to add things like strings and images to the resource file. After you build this it should provide static access to the resources (it typically generates a code file from the resources for you so you don't have to access ResourceManager yourself).

E.G. If I made resources.resx with a string called MyConfigValue after a build I should be able to access this like:

textBox.Text = Resources.MyConfigValue;

If you want values that are kinda variable but shouldn't be configurable then this is the right place to put them.


share|improve this answer
I rephrased the question in order not to upset people. –  Wamiduku Dec 4 '09 at 13:41
I'm not upset. I just want to know why you think it is unprofessional. This is probably key to why people (me included) are misunderstanding the reasoning behind your question. What kind of data are you storing inside your "config" file? –  Quibblesome Dec 4 '09 at 13:50
Something like "less neat when there is no need for the user to change the config" is what I should have written from the beginning, not "unproffessional". My apologies for being unclear. The data that ends up in the .config is VS generated. In general, aaronls describes just what I wanted to say. –  Wamiduku Dec 4 '09 at 14:30
k, let me re-jig my answer to more correctly address your q. –  Quibblesome Dec 4 '09 at 14:51
Thx, I think I'll do that. Whenever VS puts something in the config, I'll make my own version of it as a resource and redirect the references from the config to the resource. –  Wamiduku Dec 4 '09 at 15:24
show 1 more comment

After considering what was written in these comments and other searching, I decided that the best way to handle my issue of wanting my Entity Framework connection string to be embedded into my executable instead of needing the MyApplication.exe.config file with my deployed solution was to created a derived class like such:

Public Class MyEFDataContainerLocal
   Inherits MyEFDataContainer

    Public Sub New()
    End Sub
End Class

I just created an Application Setting of type Connection String that contained the same string as what is found in the App.Config file. I just had to replace the &quote;'s with actual quotes.

Then whenever I wanted to use the MyEFDataContainer as in Dim db As New MyEFDataContainer I would just use Dim db As New MyEFDataContainerLocal instead.

share|improve this answer
add comment

Here's another factor to consider. Seasoned .Net developers are accustomed to the standard application design, which incorporates using config files in both web apps and desktop apps. If you depart from that practice, you will make it more difficult for any developers who follow you to understand what you have done. Even sa's on the web server may be confused by the absence of a config file.

Since pretty much everybody does it this way, your code does not look "untidy" to others. On the contrary, it would be befuddling not to see a config file where one is expected.

share|improve this answer
add comment

It isn't unprofessional to have an app.config file shipped alongside your exe. I think the word you may be looking for is untidy. I personally don't find this is the case myself however everyone is different! Perhaps you could simply make the app.config file hidden by default?

Or another alternative is to create your own config file which you could save to the App Data folder or even storing the settings in the registry instead.

share|improve this answer
+1 for giving registry as an option which really answer's OP's question (not that I'd like this option very much). –  Sorin Comanescu Dec 4 '09 at 14:38
There's a few things in .Net that are configured in the app.config by default, but you don't need for the user to change it. Things like Enterprise Library Cryptography key and algorithm for example. It would be nice to be able to choose to embed it in your exe, since it's easy for the user to lose the app.config and break the exe. –  didibus Aug 23 '13 at 20:47
add comment

Typically the theory of a configuration file, is that it stores settings you may want to change once you've deployed the application (for something like user preferences). To do this, you need to be storing somewhere external to your application. If you use the default setup, you get "[Your].exe.config". There are many other options you could look at, but nearly every one of them ends up with a file written somewhere, if you providing a mechanism that saves settings of some kind.

share|improve this answer
add comment

I agree with serhio darasd and Quibblesome but you can just delete "solve_np.exe.config" and it'll just use default configs.

share|improve this answer
add comment

surely if it's embedded in the exe, then it is no longer configurable?

share|improve this answer
add comment

Your Answer


