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 con开发者_StackOverflow中文版fig file called settings.config as opposed to myApplication.exe.config?
Cheers
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.
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.
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.
精彩评论