配置多个.Net应用程序的最佳方法 [英] Best Approach For Configuring Multiple .Net Applications

查看:115
本文介绍了配置多个.Net应用程序的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一套互连的.Net 3.5应用程序。有些是网站,有些是网络服务,有些是Windows应用程序。每个应用程序目前都有自己的配置文件(app.config或web.config),并且当前有一些重复的键在配置文件(目前保持同步手动),因为多个应用程序需要相同的配置值。此外,此套应用程序部署在各种环境中(开发,测试,实时等)

We have a suite of interlinked .Net 3.5 applications. Some are web sites, some are web services, and some are windows applications. Each app currently has its own configuration file (app.config or web.config), and currently there are some duplicate keys across the config files (which at the moment are kept in sync manually) as multiple apps require the same config value. Also, this suite of applications is deployed across various envrionemnts (dev, test, live etc)

什么是从单个管理这些多个应用程序的配置的最佳方法配置源,因此如果需要,可以在多个应用程序之间共享配置值?我们还希望为每个环境分别配置(因此,在部署时,您不必手动更改特定于环境的配置值,例如conenction字符串),但是同时不想维护多个大配置

What is the best approach to managing the configuration of these multiple apps from a single configuration source, so configuration values can be shared between multiple apps if required? We would also like to have separate configs for each environment (so when deploying you don't have to manually change certain config values that are environment specific such as conenction strings), but at the same time don't want to maintain multiple large config files (one for each environment) as keeping this in sync when adding new config keys will prove troublesome.

推荐答案

我们使用文件模板(一个用于每个环境),当添加新的配置密钥时,例如MyApp.config.template和MyWeb.config.template,其中NAnt属性用于在环境之间不同的位。所以模板文件可能看起来有点像这样:

We use file templates such as MyApp.config.template and MyWeb.config.template with NAnt properties for the bits that are different between environments. So the template file might look a bit like this:

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

在构建过程中,我们通过循环遍历NAnt中的每个环境来生成不同环境的所有配置脚本,更改每个环境的NAnt属性$ {DbConnString}和$ {WebServiceUri}的值(实际上,这些都设置在单个文件中,每个环境都有一些部分),并使用选项展开属性打开。

During a build we generate all the configs for the different environments by just looping through each environment in a NAnt script, changing the value of the NAnt properties ${DbConnString} and ${WebServiceUri} for each environment (in fact these are all set in a single file with sections for each environment), and doing a NAnt copy with the option to expand properties turned on.

它花了一段时间来设置,但它已经支付了我们回来至少十倍的时间节省了不同版本的配置文件。

It took a little while to get set up but it has paid us back at least tenfold in the amount of time saved messing around with different versions of config files.

这篇关于配置多个.Net应用程序的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆