Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 995
Paweł Sołtysiak Avatar asked May 22 '11 18:05

Paweł Sołtysiak


2 Answers

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
like image 83
Lasse V. Karlsen Avatar answered Sep 28 '22 23:09

Lasse V. Karlsen


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.

like image 31
Tieson T. Avatar answered Sep 28 '22 22:09

Tieson T.