App.Config Magic

My blog has moved.
You can view this post at the following address:
http://www.osherove.com/blog/2003/2/22/appconfig-magic.html
Published Saturday, February 22, 2003 8:55 PM by RoyOsherove

Comments

Thursday, October 02, 2003 11:22 PM by Ritesh Arora

# re: App.Config Magic

My VB.Net application creates and uses a config File.
Now I am at cleint site and when I build my project my .config gets deleted from the Bin folder.
I even copy it to bin folder and add to project but it gets deleted on build.

I doubt if it something withthe .Net Dev Env version.. i m using .Net 1.1 now.
When I add a new application Configuration File from my project, rename it to my application name and build it gets deleted from bin folder.
Can you help me with this, why this is happening ?

Waiting for your response.
Please respond at : ritesh.arora@ubs.com

Regards,
Ritesh
Wednesday, March 31, 2004 11:33 AM by Ivan Hawkes

# re: App.Config Magic

Hi Ritish,

You probably know this by now...

Version 1.1. of the .NET environment will delete your app.config file each time you compile the code. Instead, add a file called app.config to your project and this will be copied in each time to the debug/release folders.
Tuesday, June 01, 2004 11:03 AM by Tony

# re: App.Config Magic

I have run into the same problem. I have added a file to the project named app.config and it does not get copied to bin/debug. I've tried various things from adding an XML file named app.config to adding an application configuration file (another file type option) named app.config. Then, I do a rebuild solution. I check the debug folder and the config file is not there. (no, not one named applicationname.exe.config either). There must be something we're missing.

Any help is appreciated.

-Tony
Thursday, June 24, 2004 12:44 PM by Shashank Chada

# re: App.Config Magic

Ivan,

thaz a coooool info.............thnx
Monday, June 28, 2004 12:11 PM by Tony

# re: App.Config Magic

Again, no config file is copied to the debug folder.

Now, if I am doing a release, it's there (in the release folder). But when I'm compiling in debug mode, it does not get coppied to the debug folder.

-Tony
Thursday, July 01, 2004 5:15 PM by ChazZ

# re: App.Config Magic

try using a post-build event in the project's properties window. something like this should do the trick
copy /Y ${projectdir}\app.config ${outputdir}\appname.exe.config

that will copy the app.config to the build dir everytime the project is built.


-ChazZ
Sunday, July 18, 2004 8:43 PM by Subu

# re: App.Config Magic

can i have multiple app.config files in a solution , if so how to read them at their level?
Monday, June 19, 2006 3:38 PM by Tom

# re: App.Config Magic

I had an out of date lesson book, and this thing really bit me on the butt.

Thanks for the tip.
Tuesday, September 26, 2006 3:27 PM by Frank

# re: App.Config Magic

You need to change the Build Action to "Content" if you want the file copied to the build target folder. Otherwise, it's just considered a developer artifact and no action will be taken.
Tuesday, September 26, 2006 3:37 PM by RoyOsherove

# re: App.Config Magic

This tip works in VS 2003, in 2005 you don't need it.

Monday, February 05, 2007 11:19 AM by SlapHead

# re: App.Config Magic

(VB2005) what about when you want to maintain 2 separate versions of app.config for both DEBUG and RELEASE? Ideally I just want to switch the build config to Release and get the alternative myapp.exe.config in the resulting package.  I've tried everything I can think of, as 2 separate content files (using exclude filters), you can't change the target folder or name!

As just 'files' added to the build, you can rename the target (so debug.config can become myapp.exe.config) but you can't specify the applicable build config (Active/Debug/Release), so you need to manually exclude/include each file .  

I just want to be able to have debug.config and release.config files in the source code, and for the appropriate one to be included in the build when I switch the configuration between Debug and Release.  I can't beleive it's so tricky - I must be missing something obvious.  Any Ideas anyone?