Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give app.config another name after build?

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

like image 236
AndrewC Avatar asked Mar 24 '10 13:03

AndrewC


3 Answers

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.

like image 107
Task Avatar answered Sep 23 '22 23:09

Task


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.

like image 25
SLaks Avatar answered Sep 26 '22 23:09

SLaks


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.

like image 45
Joshua Jewell Avatar answered Sep 25 '22 23:09

Joshua Jewell