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 / CLR / October 2006

Tip: Looking for answers? Try searching our database.

Environment-specific config files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kh - 19 Oct 2006 09:08 GMT
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
Bryan Phillips - 19 Oct 2006 15:13 GMT
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

> 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
[quoted text clipped - 11 lines]
>
> kh
Steven Cheng[MSFT] - 20 Oct 2006 05:09 GMT
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.
Steven Cheng[MSFT] - 24 Oct 2006 07:44 GMT
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.

Rate this thread:







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.