Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to have directives in the app.config file? I need to switch between the DB connect string for development and production. I thought it would be easy if there were something along the lines of:

#Ifdef Debug
connectstring = test
#else
connectstring = prod
#enddef
Posted

It just crossed my mind that in Web, we have this Web.config.debug & We.config.release. Probably, something similar might be there in Winforms too.

I Googled it, and came across this like[^] which looks useful discussing something similar. Have a look!
 
Share this answer
 
No, since an app.config file is never compiled by the compiler, putting compiler directives in it won't work.

You can, however, setup compiler directives in the code that loads values from the app.config file. You'd of course, have to define both production and debug values into the app.config in order for it to work.

But, there's a problem with all of this. You'd have to remove the debug values from the app.config file before you package and deploy the app.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900