开源存储库中的Web.config

时间:2022-09-05 20:20:19

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:

建议的方法如下:

  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. 创建您希望人们用作起点的文件的公共版本的副本,并将其命名为实际可用文件以外的其他内容。在您的情况下,它可能是web.config.template。如果您刚刚重命名该文件,请确保该文件可用。
  3. Instruct Mercurial to ignore the actual file, ie. web.config
  4. 指示Mercurial忽略实际文件,即。 web.config中
  5. 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
  6. 如果可能的话,如果实际文件存在,则使构建过程弄清楚,如果不存在,则从模板文件复制到实际文件中
  7. 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.
  8. 如果无法执行第3步,则创建实际文件的批处理文件是下一个最佳选择,或者是如何制作它的简单说明。

This ensures that:

这可以确保:

  1. There is a simple way of getting the actual configuration file
  2. 有一种获取实际配置文件的简单方法
  3. You can edit your local actual configuration file without worrying about committing it (it is ignored)
  4. 您可以编辑本地实际配置文件,而无需担心提交(忽略它)
  5. If step 3 was possible, this is largely transparent unless you need to make modifications to the file
  6. 如果可以执行第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:

建议的方法如下:

  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. 创建您希望人们用作起点的文件的公共版本的副本,并将其命名为实际可用文件以外的其他内容。在您的情况下,它可能是web.config.template。如果您刚刚重命名该文件,请确保该文件可用。
  3. Instruct Mercurial to ignore the actual file, ie. web.config
  4. 指示Mercurial忽略实际文件,即。 web.config中
  5. 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
  6. 如果可能的话,如果实际文件存在,则使构建过程弄清楚,如果不存在,则从模板文件复制到实际文件中
  7. 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.
  8. 如果无法执行第3步,则创建实际文件的批处理文件是下一个最佳选择,或者是如何制作它的简单说明。

This ensures that:

这可以确保:

  1. There is a simple way of getting the actual configuration file
  2. 有一种获取实际配置文件的简单方法
  3. You can edit your local actual configuration file without worrying about committing it (it is ignored)
  4. 您可以编辑本地实际配置文件,而无需担心提交(忽略它)
  5. If step 3 was possible, this is largely transparent unless you need to make modifications to the file
  6. 如果可以执行第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.

您可以将通用版本提交到您的存储库,可能仅在初始加载时(以便项目将为那些不知道如何创建自己的项目构建),然后稍后添加一个忽略规则,以便您可以添加连接字符串等等。