I am creating web application in C# using ASP.NET MVC and I am using MSSQL server installed on my machine.
我正在使用ASP.NET MVC在C#中创建Web应用程序,我正在使用我的机器上安装的MSSQL服务器。
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).
我还想将应用程序发布为开源项目,并在生产服务器上运行它。我应该将web.config文件添加到源代码存储库吗?如果我应该,我应该如何跟踪“开源版本”(指向安装在localhost上的MsSQL)和生产版本(指向我托管的web.config(我正在使用Mercurial))。
2 个解决方案
#1
3
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. - 创建您希望人们用作起点的文件的公共版本的副本,并将其命名为实际可用文件以外的其他内容。在您的情况下,它可能是web.config.template。如果您刚刚重命名该文件,请确保该文件可用。
- Instruct Mercurial to ignore the actual file, ie.
web.config
- 指示Mercurial忽略实际文件,即。 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.
- 如果无法执行第3步,则创建实际文件的批处理文件是下一个最佳选择,或者是如何制作它的简单说明。
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
- 如果可以执行第3步,除非您需要对文件进行修改,否则这在很大程度上是透明的
Step 3 can be handled with a pre-build event for your project, something like:
可以使用项目的预构建事件处理步骤3,例如:
if not exist web.config copy web.config.template web.config
#2
2
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.
您可以将通用版本提交到您的存储库,可能仅在初始加载时(以便项目将为那些不知道如何创建自己的项目构建),然后稍后添加一个忽略规则,以便您可以添加连接字符串等等。
#1
3
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. - 创建您希望人们用作起点的文件的公共版本的副本,并将其命名为实际可用文件以外的其他内容。在您的情况下,它可能是web.config.template。如果您刚刚重命名该文件,请确保该文件可用。
- Instruct Mercurial to ignore the actual file, ie.
web.config
- 指示Mercurial忽略实际文件,即。 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.
- 如果无法执行第3步,则创建实际文件的批处理文件是下一个最佳选择,或者是如何制作它的简单说明。
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
- 如果可以执行第3步,除非您需要对文件进行修改,否则这在很大程度上是透明的
Step 3 can be handled with a pre-build event for your project, something like:
可以使用项目的预构建事件处理步骤3,例如:
if not exist web.config copy web.config.template web.config
#2
2
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.
您可以将通用版本提交到您的存储库,可能仅在初始加载时(以便项目将为那些不知道如何创建自己的项目构建),然后稍后添加一个忽略规则,以便您可以添加连接字符串等等。