Best Approach for Configuring Multiple .Net Applications

We have a set of interconnected .Net 3.5 applications. Some of them are websites, some are web services, and some are Windows applications. Each application currently has its own configuration file (app.config or web.config), and there are currently several duplicate keys in the configuration files (which are currently manually synchronized), since multiple applications require the same configuration value. In addition, this set of applications is deployed through various envrionemnts (dev, test, live, etc.).

What is the best approach for managing the configuration of these multiple applications from a single configuration source, so can configuration values โ€‹โ€‹be shared among multiple applications if necessary? We would also like to have separate configurations for each environment (therefore, during deployment you do not need to manually change certain configuration values โ€‹โ€‹specific to the environment, such as connection strings), but at the same time do not want to support several large configurations of files (one for each environment), since this synchronization when adding new configuration keys will be difficult.

+4
source share
5 answers

We use file templates such as MyApp.config.template and MyWeb.config.template, with NAnt properties for bits that are different from each other. Therefore, the template file may look something like this:

<MyAppConfig> <DbConnString>${DbConnString}</DbConnString> <WebServiceUri uri="${WebServiceUri}" /> </MyAppConfig> 

During the build, we generate all the configs for different environments, simply iterating over each environment in an NAnt script, changing the value of the NAnt $ {DbConnString} and $ {WebServiceUri} properties for each environment (in fact, they are all set in the same file with sections for each environment ) and make a copy of NAnt with the ability to extend the properties included.

It took a little time to set up, but he paid us at least ten times in the time spent using different versions of the configuration files.

+1
source

Visual Studio has a relatively obscure feature that allows you to add existing elements as links that should do what you are looking for. For more, see Derick Whittaker's post on this topic.

Visual Studio really should make this option more visible. No one thinks clicking on this little arrow next to the "Add" button.

+7
source

You can split App.config into several configuration files. You simply specify the name of the file containing the configuration section.

Change app.config:

 <SomeConfigSection> <SettingA/> <SettingB/> </SomeConfigSection> <OtherSection> <SettingX/> </OtherSection> 

In app.config and SomeSetting.xml:

 <SomeConfigSection file="SomeSetting.xml" /> <OtherSection file="Other.xml" /> 

Where SomeSetting.xml contains:

Now you can compile your app.config file from different partition files using any build or deployment script. For instance:.

 if debug copy SomeSettingDebug.xml deploydir/SomeSetting.xml if MySql copy OtherSectionMySql.xml deploydir/OtherSetting.xml 
+3
source
+1
source

Check the prism structure from the Microsoft Patterns and Practices group?

0
source

Source: https://habr.com/ru/post/1276885/


All Articles