.NET Configuration (app.config/web.config/settings.settings)

后端 未结 13 1299
广开言路
广开言路 2020-11-29 14:41

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 d

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 15:15

    Any configuration that might differ across environments should be 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

    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.

    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.

    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.)

提交回复
热议问题