开发者

Web.config in open source repository

I am creating web application in C# using ASP.NET MVC and I am using MSSQL server installed on my machine.

Also I wanted to publish application as open source project, and run it on production server. Should I add web.config file to source code repository? If i should, how I should track "open source version"开发者_运维问答 (pointing on MsSQL installed on localhost) and production version (pointing on my hosting of web.config (I am using Mercurial).


The recommended way to do this is as follows:

  1. Create a copy of the public version of the file you'd like people to use as a starting point, and name it something other than the actual usable file. In your case, it could be web.config.template. Make sure the file would be usable if you just renamed it.
  2. Instruct Mercurial to ignore the actual file, ie. web.config
  3. If possible, make the build process figure out if the actual file is present, and if not, make a copy from the template file into the actual file
  4. If step 3 is not possible, a batch file to make the actual file is the next best thing, or simple instructions on how to make it.

This ensures that:

  1. There is a simple way of getting the actual configuration file
  2. You can edit your local actual configuration file without worrying about committing it (it is ignored)
  3. If step 3 was possible, this is largely transparent unless you need to make modifications to the file

Step 3 can be handled with a pre-build event for your project, something like:

if not exist web.config copy web.config.template web.config


You could commit a generic version to your repository, probably on the initial load only (so that the project will build for those who don't know how to create their own), and then add an ignore rule later so that you can add your connection strings and whatnot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜