How do you deal with configuration files in source control?

前端 未结 19 2003
情书的邮戳
情书的邮戳 2020-11-27 13:00

Let\'s say you have a typical web app and with a file configuration.whatever. Every developer working on the project will have one version for their dev boxes, there will be

19条回答
  •  一生所求
    2020-11-27 13:31

    I have always kept all versions of the config files in source control, in the same folder as the web.config file.

    For example

    web.config
    web.qa.config
    web.staging.config
    web.production.config
    

    I prefer this naming convention (as opposed to web.config.production or production.web.config) because

    • It keeps the files together when you sort by file name
    • It keeps the files together when you sort by file extension
    • If the file accidentally gets pushed to production, you won't be able to see the contents over http because IIS will prevent *.config files from being served

    The default config file should be configured such that you can run the application locally on your own machine.

    Most importantly, these files should be almost 100% identical in every aspect, even formatting. You shouldn't use tabs in one version and spaces in another for indenting. You should be able to run a diff tool against the files to see exactly what is different between them. I prefer to use WinMerge for diffing the files.

    When your build process creates the binaries, there should be a task that overwrites the web.config with the config file appropriate for that environment. If the files are zipped up, then the non relevant files should be deleted from that build.

提交回复
热议问题