Why do you have to modify the config files anyway? In the
past this is what I have done. Created custom config sections in the app.config or
web.config file tied to NameValueHandlers (Google for “custom config
files c#”). Then I create a general section that contains the environment
name and the machines that are contained in it. There is no need to be
inclusive, I only add the machines from the integrations, staging and
production environment here, everyone else become development. In my code I
retrieve the various values I need, such as database connection strings from
the section based on the machine name the code is executing on. Another method
is to the file attribute and have developer override productions settings on
their machines only (http://www.devx.com/vb2themax/Tip/18880).
Just make sure no none checks them into CVS. This way you can avoid having to do any work with the config
file at all. Derek NameValueCollection customConfigSection =
(NameValueCollection)ConfigurationSettings.GetConfig ( GetEnvironment() ); public static string GetEnvironment ( ) { string
machinename = System.Environment.MachineName;
NameValueCollection customConfigSection =
(NameValueCollection)ConfigurationSettings.GetConfig ( "General" ); if (
customConfigSection.Get( "Integration" ).IndexOf ( machinename )
>= 0 )
return "Integration"; if (
customConfigSection.Get( "Production" ).IndexOf ( machinename ) >=
0 )
return "Production"; return
"Development"; } <General> <add
key="Integration" value="SomeMachineName"/> <add
key="Production" value="SomeOtherMachineName"/> </General>
<Development> <add
key="ConnectionString" value="Provider=SQLOLEDB.1;Server=SERVER;Initial
Catalog=DB;" /> <add
key="WebServerName" value="localhost" /> </Development> <Integration> <add
key="ConnectionString"
value="Provider=SQLOLEDB.1;Server=SERVER;Initial Catalog=DB;" /> <add
key="WebServerName" value="localhost" /> </Integration> <Production> <add
key="ConnectionString"
value="Provider=SQLOLEDB.1;Server=SERVER;Initial Catalog=DB;" /> <add
key="WebServerName" value="localhost" /> </Production> |