PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

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

 
 
thalion77@graffiti.net
Guest
Posts: n/a
 
      10th Jul 2007
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

 
Reply With Quote
 
 
 
 
Michael Nemtsev
Guest
Posts: n/a
 
      10th Jul 2007
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


 
Reply With Quote
 
 
 
 
John Saunders [MVP]
Guest
Posts: n/a
 
      10th Jul 2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
--
John Saunders [MVP]

 
Reply With Quote
 
Chris Mullins [MVP]
Guest
Posts: n/a
 
      10th Jul 2007
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.

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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Chris Mullins [MVP]
Guest
Posts: n/a
 
      10th Jul 2007
I hadn't thought of that one. That's a good way to go...

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

"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
news:(E-Mail Removed)...
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
> --
> John Saunders [MVP]
>



 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      10th Jul 2007
"Chris Mullins [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
--
John Saunders [MVP]


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using 2 different ip configurations on one pc Roger Rogerson Windows XP Networking 5 17th Sep 2004 06:34 PM
can I use different references for different configurations Atara Microsoft VB .NET 7 11th Mar 2004 04:15 PM
Using config files other than app.config for different configurations Matthew Microsoft VB .NET 0 27th Jan 2004 11:53 PM
Different app.configs for different build configurations? n_o_s_p_a__m Microsoft C# .NET 2 19th Jan 2004 09:19 PM
Different configurations for different users jon.allwright Windows XP Help 1 22nd Dec 2003 11:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.