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

查看:26
本文介绍了配置多个 .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)

从单个配置源管理这些多个应用程序的配置的最佳方法是什么,以便在需要时可以在多个应用程序之间共享配置值?我们还希望为每个环境拥有单独的配置(因此在部署时您不必手动更改特定于环境的某些配置值,例如连接字符串),但同时又不想维护多个大型配置文件(每个环境一个),因为在添加新配置键时保持同步会很麻烦.

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} 的值(实际上这些是所有这些都设置在一个包含每个环境部分的单个文件中),并执行 NAnt 复制并打开扩展属性的选项.

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天全站免登陆