views:

170

answers:

3

As you all know, when you build a project with an app.config file it gets copied to the bin directory and renamed $(targetFileName).config.

Is it possible for it to be called something else?

For example if my executable is called myApplication.exe, can I have the config file called settings.config as opposed to myApplication.exe.config?

Cheers

+1  A: 

You can make a post-build step to rename the file.

Note that .Net will only read configuration files with the same name as the EXE.
Therefore, renaming it will only be useful if you have your own code to read the file.

SLaks
+3  A: 

An application by the name of 'myApplication.exe' expects the configuration file to be named 'myApplication.exe.config'. If it's named anything else, then it won't find the configuration file.

So yes, you can change it to anything else. But then it won't work.

Task
@Task Yes, I meant can it be changed and still work. I knew that .net searches for the specific name, I was curious if it could be set to look for a different name.Cheers for the answer :)
AndyC
Sure, no problem. If you absolutely have to specify the name of the config file for whatever reason, then you get into messy stuff like this: http://blogs.msdn.com/suzcook/archive/2003/06/02/57160.aspxReally not worth the effort.
Task
A: 

If you rename the file app.config located in the Solution to another name then you will no longer get the myApplication.exe.config file generated. To get your config file to be copied to the output directory right click the newName.config. And then change the attribute "Copy to Output Directory" to "Copy Always"

Keep in mind that myApplication.exe.config is a predetermined way for C# applications to load some config settings. If it does not find a config file that matches its own name nothing will be loaded automatically.

Hope this helps.

Joshua Jewell