半可编辑文件(例如配置文件)和版本控制 - 最佳实践?

时间:2023-01-12 23:49:30

So, I killed the build today by checking in a config file. It knows where the server is (think SQL server or the like), and I've been working against the server which runs on my box. Normally, or rather, under other circumstances, we'd run against the central server. The daily build, of course, didn't find 'my' server, hence the breakage. Then again, editing the config file to point to the 'normal' server before the checkin, and editing it again after checkin is tendious.

所以,我今天通过检查配置文件杀死了构建。它知道服务器在哪里(想想SQL服务器等),而且我一直在反对在我的盒子上运行的服务器。通常,或者更确切地说,在其他情况下,我们会针对*服务器运行。当然,每日构建没有找到“我的”服务器,因此破损。然后,再次编辑配置文件以在签入之前指向“正常”服务器,并在签入之后再次编辑它。

I've been tempted to have VC just ignore the config file, so that it doesn't get checked in accidentally. On the other hand, the repository should contain a clean, usable version of the file. I can't possibly ignore it and have it checked in at the same time, now, could I?

我一直想让VC忽略配置文件,这样就不会意外地检查它。另一方面,存储库应包含一个干净,可用的文件版本。我不可能忽略它并同时检查它,现在,我可以吗?

So, what I'm looking for would be a way to have a file which, errr, which checks out, but never checks in. At least in the most common case - should the config file change significantly, some special procedure to get the new version into the repository would be doable.

所以,我正在寻找的是一种方法,有一个文件,错误,检查,但永远不会检入。至少在最常见的情况下 - 如果配置文件发生重大变化,一些特殊的程序,以获得进入存储库的新版本是可行的。

If You folks have come across this problem before, I'd be interested about any solutions You have found. As long as they don't break the build, that is ;)

如果您以前遇到过这个问题,我会对您找到的任何解决方案感兴趣。只要他们不打破构建,那就是;)

8 个解决方案

#1


What you can do is have a default config file that stays unchanged, unless some new config is added. Then you have a different file that overrides the default file's configs.

除非添加了一些新配置,否则您可以执行的默认配置文件保持不变。然后你有一个不同的文件覆盖默认文件的配置。

config.Default.xml
config.User.xml

Only config.Default.xml is source controlled. config.User.xml contains only the configurations that are different for you. So, say you are testing on a local SQL server, you put only the connection string in there and it will override the config.Default connection string.

只有config.Default.xml是源控制的。 config.User.xml仅包含不同的配置。因此,假设您正在本地SQL服务器上进行测试,您只将连接字符串放在那里,它将覆盖config.Default连接字符串。

Take a look at .Net Framwork Application Configuration, it does most (if not all) of the work for you.

看看.Net Framwork Application Configuration,它可以为您完成大部分(如果不是全部)工作。

#2


One method I've used is to have two versions of the config file, and have the installer script pull the correct version.

我使用的一种方法是拥有两个版本的配置文件,并让安装程序脚本提取正确的版本。

  • settings.xml
  • settings.xml-Release

Both files contain the same keys, but one contains 'dev' values and the other contains the values we expect to deploy and be edited in the field.

两个文件都包含相同的键,但其中一个包含'dev'值,另一个包含我们期望部署的值并在字段中进行编辑。

#3


We store these sort of files in our source control system, and have different folders for the environment we're building for.

我们将这些类型的文件存储在我们的源代码管理系统中,并为我们正在构建的环境提供不同的文件夹。

So we have:

所以我们有:

Dev
Test
Live

There are subfolders under these for other environment specific files.

其他环境特定文件下有子文件夹。

#4


We have

  • *.(config | xml)
  • *。(config | xml)

  • *.(config | xml).cert
  • *。(config | xml).cert

  • *.(config | xml).production
  • *。(config | xml).production

Hudson deletes the initial file and deploys the correct file for the correct environment (currently only cert).

Hudson删除初始文件并为正确的环境部署正确的文件(目前只有cert)。

This allows developers to document and develop production, cert and development level config files independently and have them versioned separately in SVN.

这允许开发人员独立地记录和开发生产,证书和开发级别的配置文件,并在SVN中单独对其进行版本控制。

#5


I think the accepted answer is good, but depending on your requirements, it may have limitations.

我认为接受的答案是好的,但根据您的要求,它可能有局限性。

We use the following approach. Note that we are .NET shop using VS and make use of MSBuild (inbuilt, community and custom) tasks.

我们使用以下方法。请注意,我们是使用VS的.NET商店,并使用MSBuild(内置,社区和自定义)任务。

  • App.config is ignored by version control but included in the project.
  • 版本控制忽略App.config但包含在项目中。

  • App.default.config is under version control and also included in the project. Instead of hard-coding things that can change, e.g. db connection strings, we use tokens instead.
  • App.default.config受版本控制,也包含在项目中。而不是对可以改变的事物进行硬编码,例如db连接字符串,我们使用令牌代替。

A project's BeforeBuild task looks for existance of App.config and if not found copies App.default.config to App.config. Also, the build server always deletes App.config if it exists on a CI build (ensures clean config). We also then use the MSBuild Community FileUpdate task to replace the tokens with the appropriate values based on whatever is building the project.

项目的BeforeBuild任务查找App.config的存在,如果没有找到,则将App.default.config复制到App.config。此外,构建服务器始终删除App.config(如果它存在于CI构建中)(确保干净配置)。然后,我们还使用MSBuild社区FileUpdate任务,根据构建项目的内容将标记替换为适当的值。

For example, a fresh developer checkout can setup db connection strings for a local database, a nightly build can setup for the nightly db, etc.

例如,一个新的开发人员结账可以为本地数据库设置数据库连接字符串,可以为每晚数据库设置每晚构建等。

#6


Were I work we have separate config files for deploys. So the config files in our solutions are the development versions and people can change them to their heart's content. These config files are never deployed anywhere.

如果我工作,我们有单独的配置文件进行部署。因此,我们解决方案中的配置文件是开发版本,人们可以根据自己的内容进行更改。这些配置文件从未在任何地方部署。

The config files that are deployed are stored in a separate location in our source control provider. If someone needs to make a config change that will be deployed they have to modify this version instead.

部署的配置文件存储在源代码管理提供程序中的单独位置。如果有人需要进行将要部署的配置更改,则必须修改此版本。

#7


The accepted answer is good. However, it is possible to do what you wanted to (4 years ago), and maintain just a single config file which checks out and never checks in -- if your version control system has the concept of changelists. I have done this in Perforce:

接受的答案是好的。但是,如果您的版本控制系统具有更改列表的概念,则可以执行您想要的操作(4年前),并且只维护一个检出并且从不签入的配置文件。我在Perforce中做到了这一点:

Check out the config file and keep it in its own changelist. When you commit, commit only the other changelists; this is easy to remember if you name your config file changelist something like "DO NOT COMMIT".

查看配置文件并将其保存在自己的更改列表中。提交时,只提交其他更改列表;如果您将配置文件更改列表命名为“DO NOT COMMIT”,则很容易记住。

An advantage of this system is that if someone else changes the production version of the config file -- i.e. the one which exists on the server, and which everyone is maintaining a modified local version of -- then you will be notified of possible conflicts when you get the config file from the server. With a solution like that suggested in the accepted answer, you might keep silently overriding the new production settings with your local settings, which could break your local build or cause you to break the build when you next commit.

此系统的一个优点是,如果其他人更改配置文件的生产版本 - 即服务器上存在的版本,以及每个人都维护修改后的本地版本 - 那么您将收到可能的冲突通知你从服务器获得配置文件。使用类似于已接受答案中建议的解决方案,您可以使用本地设置静默覆盖新的生产设置,这可能会破坏您的本地构建或导致您在下次提交时中断构建。

#8


For each configuration file x, create a file that you do check-in called x.dist, which is the default distributed configuration. After the developers check out, have a script that copies each x.dist file to x, where they can customize x as much as necessary. This script can be re-run to update the files following major changes, or developers can manually merge in their changes.

对于每个配置文件x,创建一个您执行签入的文件x.dist,这是默认的分布式配置。开发人员签出后,有一个脚本将每个x.dist文件复制到x,他们可以根据需要自定义x。可以重新运行此脚本以在主要更改后更新文件,或者开发人员可以手动合并其更改。

For deployment, you can check in your live deployment files and have your start-up scripts refer to them explicitly (e.g. --config x.production).

对于部署,您可以签入实时部署文件,并让您的启动脚本明确引用它们(例如--config x.production)。

This approach is used, for example, in how Wordpress is distributed (you must copy a template wp-config.php file) or in development projects that use autoconf (where the configure.ac is checked in but the configure file must be generated by each developer; a special configure file is built for distribution in tarballs at release time).

例如,这种方法用于如何分发Wordpress(您必须复制模板wp-config.php文件)或在使用autoconf的开发项目中(其中configure.ac已签入但配置文件必须由每个开发人员;构建一个特殊的配置文件,以便在发布时在tarball中分发)。

#1


What you can do is have a default config file that stays unchanged, unless some new config is added. Then you have a different file that overrides the default file's configs.

除非添加了一些新配置,否则您可以执行的默认配置文件保持不变。然后你有一个不同的文件覆盖默认文件的配置。

config.Default.xml
config.User.xml

Only config.Default.xml is source controlled. config.User.xml contains only the configurations that are different for you. So, say you are testing on a local SQL server, you put only the connection string in there and it will override the config.Default connection string.

只有config.Default.xml是源控制的。 config.User.xml仅包含不同的配置。因此,假设您正在本地SQL服务器上进行测试,您只将连接字符串放在那里,它将覆盖config.Default连接字符串。

Take a look at .Net Framwork Application Configuration, it does most (if not all) of the work for you.

看看.Net Framwork Application Configuration,它可以为您完成大部分(如果不是全部)工作。

#2


One method I've used is to have two versions of the config file, and have the installer script pull the correct version.

我使用的一种方法是拥有两个版本的配置文件,并让安装程序脚本提取正确的版本。

  • settings.xml
  • settings.xml-Release

Both files contain the same keys, but one contains 'dev' values and the other contains the values we expect to deploy and be edited in the field.

两个文件都包含相同的键,但其中一个包含'dev'值,另一个包含我们期望部署的值并在字段中进行编辑。

#3


We store these sort of files in our source control system, and have different folders for the environment we're building for.

我们将这些类型的文件存储在我们的源代码管理系统中,并为我们正在构建的环境提供不同的文件夹。

So we have:

所以我们有:

Dev
Test
Live

There are subfolders under these for other environment specific files.

其他环境特定文件下有子文件夹。

#4


We have

  • *.(config | xml)
  • *。(config | xml)

  • *.(config | xml).cert
  • *。(config | xml).cert

  • *.(config | xml).production
  • *。(config | xml).production

Hudson deletes the initial file and deploys the correct file for the correct environment (currently only cert).

Hudson删除初始文件并为正确的环境部署正确的文件(目前只有cert)。

This allows developers to document and develop production, cert and development level config files independently and have them versioned separately in SVN.

这允许开发人员独立地记录和开发生产,证书和开发级别的配置文件,并在SVN中单独对其进行版本控制。

#5


I think the accepted answer is good, but depending on your requirements, it may have limitations.

我认为接受的答案是好的,但根据您的要求,它可能有局限性。

We use the following approach. Note that we are .NET shop using VS and make use of MSBuild (inbuilt, community and custom) tasks.

我们使用以下方法。请注意,我们是使用VS的.NET商店,并使用MSBuild(内置,社区和自定义)任务。

  • App.config is ignored by version control but included in the project.
  • 版本控制忽略App.config但包含在项目中。

  • App.default.config is under version control and also included in the project. Instead of hard-coding things that can change, e.g. db connection strings, we use tokens instead.
  • App.default.config受版本控制,也包含在项目中。而不是对可以改变的事物进行硬编码,例如db连接字符串,我们使用令牌代替。

A project's BeforeBuild task looks for existance of App.config and if not found copies App.default.config to App.config. Also, the build server always deletes App.config if it exists on a CI build (ensures clean config). We also then use the MSBuild Community FileUpdate task to replace the tokens with the appropriate values based on whatever is building the project.

项目的BeforeBuild任务查找App.config的存在,如果没有找到,则将App.default.config复制到App.config。此外,构建服务器始终删除App.config(如果它存在于CI构建中)(确保干净配置)。然后,我们还使用MSBuild社区FileUpdate任务,根据构建项目的内容将标记替换为适当的值。

For example, a fresh developer checkout can setup db connection strings for a local database, a nightly build can setup for the nightly db, etc.

例如,一个新的开发人员结账可以为本地数据库设置数据库连接字符串,可以为每晚数据库设置每晚构建等。

#6


Were I work we have separate config files for deploys. So the config files in our solutions are the development versions and people can change them to their heart's content. These config files are never deployed anywhere.

如果我工作,我们有单独的配置文件进行部署。因此,我们解决方案中的配置文件是开发版本,人们可以根据自己的内容进行更改。这些配置文件从未在任何地方部署。

The config files that are deployed are stored in a separate location in our source control provider. If someone needs to make a config change that will be deployed they have to modify this version instead.

部署的配置文件存储在源代码管理提供程序中的单独位置。如果有人需要进行将要部署的配置更改,则必须修改此版本。

#7


The accepted answer is good. However, it is possible to do what you wanted to (4 years ago), and maintain just a single config file which checks out and never checks in -- if your version control system has the concept of changelists. I have done this in Perforce:

接受的答案是好的。但是,如果您的版本控制系统具有更改列表的概念,则可以执行您想要的操作(4年前),并且只维护一个检出并且从不签入的配置文件。我在Perforce中做到了这一点:

Check out the config file and keep it in its own changelist. When you commit, commit only the other changelists; this is easy to remember if you name your config file changelist something like "DO NOT COMMIT".

查看配置文件并将其保存在自己的更改列表中。提交时,只提交其他更改列表;如果您将配置文件更改列表命名为“DO NOT COMMIT”,则很容易记住。

An advantage of this system is that if someone else changes the production version of the config file -- i.e. the one which exists on the server, and which everyone is maintaining a modified local version of -- then you will be notified of possible conflicts when you get the config file from the server. With a solution like that suggested in the accepted answer, you might keep silently overriding the new production settings with your local settings, which could break your local build or cause you to break the build when you next commit.

此系统的一个优点是,如果其他人更改配置文件的生产版本 - 即服务器上存在的版本,以及每个人都维护修改后的本地版本 - 那么您将收到可能的冲突通知你从服务器获得配置文件。使用类似于已接受答案中建议的解决方案,您可以使用本地设置静默覆盖新的生产设置,这可能会破坏您的本地构建或导致您在下次提交时中断构建。

#8


For each configuration file x, create a file that you do check-in called x.dist, which is the default distributed configuration. After the developers check out, have a script that copies each x.dist file to x, where they can customize x as much as necessary. This script can be re-run to update the files following major changes, or developers can manually merge in their changes.

对于每个配置文件x,创建一个您执行签入的文件x.dist,这是默认的分布式配置。开发人员签出后,有一个脚本将每个x.dist文件复制到x,他们可以根据需要自定义x。可以重新运行此脚本以在主要更改后更新文件,或者开发人员可以手动合并其更改。

For deployment, you can check in your live deployment files and have your start-up scripts refer to them explicitly (e.g. --config x.production).

对于部署,您可以签入实时部署文件,并让您的启动脚本明确引用它们(例如--config x.production)。

This approach is used, for example, in how Wordpress is distributed (you must copy a template wp-config.php file) or in development projects that use autoconf (where the configure.ac is checked in but the configure file must be generated by each developer; a special configure file is built for distribution in tarballs at release time).

例如,这种方法用于如何分发Wordpress(您必须复制模板wp-config.php文件)或在使用autoconf的开发项目中(其中configure.ac已签入但配置文件必须由每个开发人员;构建一个特殊的配置文件,以便在发布时在tarball中分发)。