.NET配置(App.config中/ web.config中/ settings.settings) [英] .NET Configuration (app.config/web.config/settings.settings)

查看:531
本文介绍了.NET配置(App.config中/ web.config中/ settings.settings)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET应用程序具有用于调试和发布版本不同的配置文件。例如。调试app.config文件指向一个发展的SQL Server 的具有调试启用,​​并公布目标点现场的SQL Server。也有其他的设置,其中一些是在调试/释放不同

I have a .NET application which has different configuration files for Debug and Release builds. E.g. the debug app.config file points to a development SQL Server which has debugging enabled and the release target points to the live SQL Server. There are also other settings, some of which are different in debug/release.

目前,我使用两个单独的配置文件(debug.app.config和release.app.config)。我对这个项目它说一个生成事件,如果这是一个发布版本然后复制release.app.config到的app.config,否则副本debug.app.config到的app.config。

I currently use two separate configuration files (debug.app.config and release.app.config). I have a build event on the project which says if this is a release build then copy release.app.config to app.config, else copy debug.app.config to app.config.

现在的问题是,应用程序似乎从settings.settings文件中获取它的设置,所以我要在Visual Studio中,然后提示我的设置已经改变,所以我接受更改,保存设置打开settings.settings。设置,必须重建,使其使用正确的设置。

The problem is that the application seems to get its settings from the settings.settings file, so I have to open settings.settings in Visual Studio which then prompts me that the settings have changed so I accept the changes, save settings.settings and have to rebuild to make it use the correct settings.

有没有更好/推荐/ preferred方法实现类似的效果?还是一样,有我走近这个完全错误的,有没有更好的方法?

Is there a better/recommended/preferred method for achieving a similar effect? Or equally, have I approached this completely wrong and is there a better approach?

推荐答案

在整个环境中可能会与任何配置应该存储在机级别,不是应用水平(在配置级别的更多信息。)

Any configuration that might differ across environments should stored at the machine level, not the application level. (More info on configuration levels.)

这些都是种配置元素,我通常存储在机器级:

These are the kinds of configuration elements that I typically store at the machine level:

  • Application settings
  • Connection strings
  • retail=true
  • Smtp settings
  • Health monitoring
  • Hosting environment
  • Machine key

在每个环境(开发,集成,测试,舞台,生活)的在ç自己独特的设定:\ WINDOWS \ Microsoft.NET \ Framework64 \ V2.0.50727 \ CONFIG 目录,然后你可以在没有任何后期修饰构建促进您的应用程序code 的环境之间。

When each environment (developer, integration, test, stage, live) has its own unique settings in the c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG directory, then you can promote your application code between environments without any post-build modifications.

和明显,本机级别CONFIG目录中的内容获取版本控制在不同的存储库中,或从你的应用程序不同的文件夹结构。你可以让你的.config文件的详细源代码控制,通过智能化的使用<友好href="http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx">configSource.

And obviously, the contents of the machine-level CONFIG directory get version-controlled in a different repository or a different folder structure from your app. You can make your .config files more source-control friendly through intelligent use of configSource.

我已经做了7年,就在25+不同的公司超过200 ASP.NET应用程序。 (不是要炫耀,只是想让你知道,我从来没有见过的情况下这种做法的的工作。)

I've been doing this for 7 years, on over 200 ASP.NET applications at 25+ different companies. (Not trying to brag, just want to let you know that I've never seen a situation where this approach doesn't work.)

这篇关于.NET配置(App.config中/ web.config中/ settings.settings)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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