We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
我正在使用 Devart CodeCompare 来完成此任务。 Native VS 编辑器让我可以很好地处理 C# 和 VB。他们将此功能称为“结构比较”。这对你很有用。
I am using Devart CodeCompare for this task. Native VS editor allows me to handle C# and VB very well. They call this feature "Structure comparison". It will be useful for you.
我认为您不会找到可以执行此操作的文本比较实用程序。您最好重新组织这些功能,使它们位于相同的位置。我见过设计者生成的代码这样做(即,每次重新生成文件时移动函数)。这很烦人,但我认为你无法回避它。 BeyondCompare 确实是最好的比较实用程序之一。
I don't think you're going to find a text compare utility that will do this. You're better off reorganizing the functions so they are in the same places. I've seen designer generated code do this (ie, move functions around every time the file gets regenerated). Its annoying, but I don't think you're going to get around it. BeyondCompare really is one of the best comparison utilities out there.
目前(2015 年 4 月),至少有 3 个商业比较工具考虑了 C# 代码文件的结构,以在代码文件之间进行高级比较和合并
这三个工具仅在付费版本(或试用期)上支持这种高级比较。 AFAIK 没有免费工具可以做到这一点。
At this moment (april 2015), there are at least 3 commercial comparison tools that have into account the structure of C# code files to make an advanced diff and merge between code files:
These three tools support this kind of advanced comparison only on the payed versions (or the trial periods). AFAIK there is no free tool that can do this.
[更新(2015):自从编写此答案以来,现在有更多现代工具可以对各种语言的代码进行结构和语义合并和比较。请参阅 JotaBe 的回答获取一些示例]
原始答案(2010):
不幸的是,这就是 Diff 的本质。它始终是逐行比较,而不是语言感知比较。据我所知,没有什么可以满足您的要求(尽管我总是有可能是错的)。
在进行比较之前,您可以使用 regionerate 之类的工具来标准化类布局。这将对所有方法进行排序,因此不会出现同名方法位于文件中不同位置的问题。
[Update (2015): Since writing this answer there are now more modern tools that can do structural and semantic merging and diffing of code in various languages. See JotaBe's answer for some examples]
Original answer (2010):
Unfortunately, that is kind of the nature of Diff. It's always been a line by line comparison, it's not a language aware comparison. As far as I am aware there is nothing that does what you are asking for (It's always possible I'm wrong though).
You could use a tool like regionerate to standardize class layout before you do the comparison. This would order all your methods, so you wouldn't have the problem with a method of the same name being in different places in a file.
我知道唯一可以做到这一点的工具(我不确定它可以)是 Git。
据我所知,即使函数被移动到不同的文件,它也可以跟踪它们,因此在这种情况下使用它不会显示出差异。
请参阅此回答以获取更多详细信息。
The only tool I am aware of that may be able to do this (I am not sure it can) is Git.
As far as I know, it can track functions even if they are moved to different files, so using it in this scenario would not show a difference.
See this answer for more detail.