How to use different .settings files for different environments in .NET?

前端 未结 6 798
温柔的废话
温柔的废话 2021-02-02 01:11

.NET allows you to use .settings files to manage application settings. I would like to store Production, Development and Test settings separately in a way that I can do somethi

6条回答
  •  故里飘歌
    2021-02-02 02:10

    There is a bit of overhead involved in making a check to determine what environment you are running in. If you are talking a web environment then this could mean a significant performance hit. I would recommend creating three separate config files and setting up a continuous integration and deployment system that handles the naming and roll out of the proper settings file based on environment. In your case you would have three files, Production.config, Development.config, and Test.config. The integration server would then create a copy of this file for web.config or app.config based on the environment.

    As far as any additional maintenance involved with maintaining three separate files whenever a configuration change is made, we keep the files auto-formatted and use something like WinMerge to easily see differences and keep them in proper sync. These type of files typically do not require many changes and when they do they are usually minor additions.

提交回复
热议问题