为什么 C# 设计器生成的代码(如 Form1.designer.cs)会对 Subversion 造成严重破坏? [英] Why does C# designer-generated code (like Form1.designer.cs) play havoc with Subversion?

查看:31
本文介绍了为什么 C# 设计器生成的代码(如 Form1.designer.cs)会对 Subversion 造成严重破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作室最近从 SourceSafe 切换到 Subversion,使我们摆脱了自动锁定.这导致了表单的并发编辑,这很棒.但是当多个开发人员提交他们的更改时,设计者创建的代码文件(所有名为 TheFormName.designer.cs 的文件)会导致很难解决的冲突.

My workshop has recently switched to Subversion from SourceSafe, freeing us from automatic locks. This led to concurrent editing of the Forms, which is wonderful. But when multiple developers commit their changes, the code files created by the designer (all the files named TheFormName.designer.cs) cause conflicts which are very difficult to resolve.

据我所知,这是因为每当用户修改代码时,设计师生成的代码都会被大量重新排列,无论实际变化有多大.

As far as I can tell, this is because the code generated by the designer is heavily re-arranged whenever the user modifies it, no matter how little the actual change really did.

  • 如何使这些冲突更容易解决?
  • 有什么方法可以告诉设计师少修改代码吗?
  • 经验丰富的 C# 团队如何处理表单的并发修改?

推荐答案

我不熟悉 C# 或 Windows 窗体设计器,但查看了一些我可以在网上找到的 designer.cs 文件没有特别复杂的结构.

I'm not familiar with C# or the Windows Form Designer, but looking at some designer.cs files I could find online they don't have a particularly complicated structure.

它的哪些部分正在重新安排?我猜主要是 InitializeComponent() 方法中的属性顺序混乱了?

What parts of it are being re-arranged? I guess it's mostly the order of the properties in the InitializeComponent() method that's jumbled up?

如果是这种情况,您可以编写一个简单的脚本,按字母顺序对这些行重新排序,比如说(特别是如果您从不手动编辑这些文件),并将其用作 Subversion 中的预提交钩子脚本.

If that's the case, you might be able to write a simple script that re-orders those lines alphabetically, say (especially if you never edit these files manually anyway), and use that as a pre-commit hook script in Subversion.

嗯,对了……从头开始.该部分底部的大红框表示您不应该修改挂钩脚本中的事务.但是您也许可以找到另一种方法来在 designer.cs 文件被更改和它被提交之间的某处运行该脚本.

Um, right... scratch that. The big red box at the bottom of that section says you're not supposed to modify transactions in hook scripts. But you might be able to find another way to run that script somewhere between the designer.cs file being changed and it being committed.

实际上,鉴于 scraimer 对此的评论:

Actually, given scraimer's comment on this:

完全破解,但在最坏的情况下,就在合并之前,我可以对两个文件进行排序,并使合并变得简单地逐行...

Total hack, but in the worst case, just before a merge, I could sort BOTH files, and make the merge simply a line-by-line affair...

不能让 Subversion 设置外部合并程序吗?我一直在使用 KDiff3,它可以 在进行差异或合并之前运行预处理器命令,以便您可以自动执行该过程.

Can't you let Subversion set an external merge program? I've been using KDiff3, which can run a preprocessor command before doing diffs or merges, so you could automate that process.

这篇关于为什么 C# 设计器生成的代码(如 Form1.designer.cs)会对 Subversion 造成严重破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆