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:
- 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. - Instruct Mercurial to ignore the actual file, ie.
web.config
- 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
- 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:
- There is a simple way of getting the actual configuration file
- You can edit your local actual configuration file without worrying about committing it (it is ignored)
- 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.
精彩评论