all groups > dotnet clr > october 2006 >
You're in the

dotnet clr

group:

Environment-specific config files



Environment-specific config files kh
10/19/2006 1:08:01 AM
dotnet clr: As with all projects, our config files need to be edited as the application
is migrated through it's various environments (e.g. connection strings for
DEV, UAT, etc.) We also have sections that are specific to particular
developers (e.g. logging paths, etc) and some sections which are owned by our
production support team (e.g. security configs).

It would therefore be useful to break the config file out into separate
files and have them merged during the build, with only those sections
relevant to the target environment included. Does anyone know of any products
or other initiatives which do something like this? We could hack around with
prebuild events but this could get messy and difficult to manage.

Thanks

kh
Re: Environment-specific config files Bryan Phillips
10/19/2006 2:13:38 PM
One trick that I have seen at a few large clients is to add an
appsetting or two to the machine.config file. In one case, the IT guys
added a key named "Environment" which had one of these values: DEV,
TEST, PROD. Then, they used a custom configuration section in the
web.config file to specify the value for each environment. Once the
application was deployed to their DEV server (for load testing, etc..),
they were not allowed to modify it without republishing due to an
internal policy.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com




[quoted text, click to view]
Re: Environment-specific config files stcheng NO[at]SPAM online.microsoft.com
10/20/2006 12:00:00 AM
Thanks for Bryan's input.

Hi Hk,

As for the projects you're currently dealing with, are they developing upon
..net framework 1.1/ vs2003 or .net framework 2.0/vs 2005. In .net framework
2.0, the new configuration system has provide the support of linking an
external file for individual configuration section in the application
config file (app.config or web.config).

#Managing Changes to Configuration Settings
http://msdn2.microsoft.com/en-us/library/ms228058.aspx

#Configuration & ASP.NET 2.0
http://odetocode.com/Blogs/scott/archive/2005/07/04/1906.aspx

The above reference has demonstrate its usage in asp.net application.
However, it also applies for most built-in configuration sections (such as
configuration Section under <system.net> , <system.diagnostics> .....).

For example, your main app.config can look like below:

======================
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings configSource="appSettings.config"></appSettings>
<connectionStrings configSource="connectionStrings.config" />


<system.diagnostics
configSource="system.diagnostics.config"></system.diagnostics>

<system.net>
<settings configSource="system.net_settings.config"></settings>
</system.net>
</configuration>
====================

The detailed settings of each section is defined in the external config
file. e.g.

=========appSettings.config==============
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="key1" value="value1"/>
<add key="key2" value="value2"/>
</appSettings>
=========================

So far I haven't found any built-in add-in that can help automatically do
this or merging separate files together. We need to do such separate
configuration ourselves.

In addition, if you're using ASP.NET 2.0, there is a add-on project called
"Web Deployment Project". This add-on project can help us do customized web
application precompilation, and one of the feature in it is let us specify
configuration section replacement at the precompile time. You can have a
look at the following article which has demonstrate the configuration
section replacement:

#VS 2005 Web Deployment Projects
http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx

Hope this helps some though it seems still far from perfect. If there is
any other questions on this, please feel free to post here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.



Re: Environment-specific config files stcheng NO[at]SPAM online.microsoft.com
10/24/2006 12:00:00 AM
Hello Bryan,

How are you doing on this issue? Have you got any progress or does the
information in my last reply helps a little?

If there is anything else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button