Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Using different configurations (web.config, app.config)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
thalion77@graffiti.net - 10 Jul 2007 09:22 GMT
Hello there,

is there a possibility to use different configurations for debug and
release mode?

I need other settings in debug mode than in release mode but do not
want to replace the web.config all the time manually.

Regards,
Norbert
Michael Nemtsev - 10 Jul 2007 09:48 GMT
Hello Norbert_Pürringer,

Nope, you can't
everything you can do is to add debug keys to the config and use them if
u in debug mode

---
WBR,  Michael  Nemtsev [.NET/C# MVP].  
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

N> Hello there,
N>
N> is there a possibility to use different configurations for debug and
N> release mode?
N>
N> I need other settings in debug mode than in release mode but do not
N> want to replace the web.config all the time manually.
N>
N> Regards,
N> Norbert
John Saunders [MVP] - 10 Jul 2007 14:04 GMT
> Hello there,
>
> is there a possibility to use different configurations for debug and
> release mode?

One thing you can do is switch appSettings using user.config:

<configuration>
   <appSettings file="user.config">
       <add key="keyName" value="releaseValue"/>
   </appSettings>
</configuration>

in user.config:

<appSettings>
   <add key="keyName" value="debugValue"/>
   <add key="otherKey" value="debugOnly"/>
</appSettings>

If user.config doesn't exist, then everything is normal. If it's present,
then its values supersede any corresponding values in the web.config.
Signature

John Saunders [MVP]

Chris Mullins [MVP] - 10 Jul 2007 18:26 GMT
I hadn't thought of that one. That's a good way to go...

Signature

Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

>> Hello there,
>>
[quoted text clipped - 18 lines]
> If user.config doesn't exist, then everything is normal. If it's present,
> then its values supersede any corresponding values in the web.config.
John Saunders [MVP] - 10 Jul 2007 20:25 GMT
>I hadn't thought of that one. That's a good way to go...

An "oldie, but a goodie", at least for appSettings.

I just took a look at Web Deployment Projects (see
http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx). Among other things,
this feature seems to allow you to replace individual sections of the
web.config file on a per-configuration basis. In particular, you can add:

appSettings="debugAppSettings.config"
system.web="debugSystem.web.config"

and reverse them for Release.
Signature

John Saunders [MVP]

Chris Mullins [MVP] - 10 Jul 2007 18:25 GMT
There are a few ways to do this that come time mind:

The first is in debug/release mode, use different key names.

You app.config would look like
<add key='option1' value='do it the easy way'/>
<add key='option1_debug' value='do it the hard way'/>

... and inside your code, have a single entry/exit point for looking up key
value.

That code will say:
string keyValue = passedInKeyValue
#if Debug
keyValue = keyValue + "_debug";
#end if
return ConfigurationManager.AppSettings[keyValue];

That would work with no trouble.

Another option is to use a custom app domain. When you create a new
application domain, you get to specify the name & location of the config
file. You could have a "loader" app domain in your Main(), that says,
AppDomain d = new AppDomain()
#if DEBUG
d.ConfigPath = "debug.config";
#else
d.ConfigPath="release.config";
#end if

... and all your "real" code runs in this new app domain.

Signature

Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

> Hello there,
>
[quoted text clipped - 6 lines]
> Regards,
> Norbert

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.