I'd like to be able to do a code-level diff between two assemblies; the Diff plug-in for Reflector is the closest thing I've found so far, but to compare the entire assembly is a manual process requiring me to drill-down into every namespace/class/method.
我希望能够在两个程序集之间做代码级的差异;Reflector的Diff插件是我迄今为止发现的最接近的东西,但是要比较整个程序集,需要我深入到每个名称空间/类/方法中。
The other tools I've found so far appear to be limited to API-level (namespaces, classes, methods) differences--which won't cut it for what I'm looking for.
到目前为止,我发现的其他工具似乎仅限于api级别(名称空间、类、方法)的差异——这并不能满足我的需求。
Does anyone know of such a tool? My requirements (from highest to lowest) are:
有人知道这种工具吗?我的要求(从最高到最低)是:
- Be able to analyze / reflect the code content of two versions of the same assembly and report the differences
- 能够分析/反映同一程序集的两个版本的代码内容并报告差异
- Accept a folder or group of assemblies as input; quickly compare them (similar to WinMerge's folder diff's)
- 接受一个文件夹或一组程序集作为输入;快速比较它们(类似于WinMerge的文件夹diff)
- Quick ability to determine if two assemblies are equivalent at the code level (not just the API's)
- 快速确定两个程序集在代码级别是否等价(不只是API)
- Allow easy drill-down to view the differences
- 允许简单的钻取来查看差异
- Exporting of reports regarding the differences
- 导出有关差异的报告。
(Personally I like WinMerge for text diffs, so an application with a similar interface would be great)
(就我个人而言,我喜欢WinMerge for text diffs,因此具有类似接口的应用程序将是非常棒的)
8 个解决方案
#1
13
The tool NDepend offers many features to handle .NET code diff.
NDepend工具提供了许多处理。net代码差异的特性。
The panel Search by Change is dedicated to browse assemblies code diff:
更改面板搜索专用于浏览程序集代码diff:
Many code rules that constraint diff and evolution are proposed. They can be a good start to write your own ones or adapt them to your needs. For example look at the rule:
提出了许多约束diff和演进的代码规则。他们可以是一个很好的开始来写你自己的书或者根据你的需要改编它们。例如,看看规则:
Types that used to be 100% covered but not anymore
类型以前是100%覆盖,但现在不是
// <Name>Types that used to be 100% covered but not anymore</Name>
warnif count > 0
from t in JustMyCode.Types where
t.IsPresentInBothBuilds() &&
t.OlderVersion().PercentageCoverage == 100 &&
t.PercentageCoverage < 100
let culpritMethods = t.Methods.Where(m => m.PercentageCoverage < 100)
select new {t, t.PercentageCoverage, culpritMethods }
or also:
或者:
- API Breaking Changes: Methods
- API打破变化:方法
- Avoid making complex methods even more complex
- 避免使复杂的方法变得更加复杂
- Avoid decreasing code coverage by tests of types
- 避免通过类型测试降低代码覆盖率
- From now, all types added or refactored should respect basic quality principles
- 从现在开始,所有添加或重构的类型都应该遵循基本的质量原则
- Avoid transforming an immutable type into a mutable one
- 避免将不可变类型转换为可变类型
- Heuristic to find types moved from one namespace or assembly to another
- 启发式查找从一个名称空间或程序集移动到另一个名称空间或程序集的类型
To get started with NDepend compare capabilities, have a look at the documentation:
要开始使用NDepend比较功能,请查看文档:
-
Advanced Code Diff from within Visual Studio: explains how to use the NDepend build comparison features, in the context of Visual Studio and Visual NDepend standalone UI.
Visual Studio中的高级代码Diff:解释如何使用NDepend构建比较特性,在Visual Studio和Visual NDepend独立UI的上下文中。
-
Reporting Code Diff: explains how to use the NDepend build comparison features, in the context of reporting.
报告代码Diff:在报告的上下文中解释了如何使用NDepend构建比较特性。
Disclaimer: I work for NDepend
免责声明:我为NDepend工作
#2
5
You can use ILDasm
to generate il source from an assembly. IL source is basically a text file, so you can compare two il files using standard text diff tools. Interpreting the IL sources may not necessary, if you use the reported diffs as an indication where to look further.
您可以使用ILDasm从程序集中生成il源代码。IL source基本上是一个文本文件,所以您可以使用标准文本diff工具比较两个IL文件。如果您使用报告的差异作为进一步研究的指示,那么解释IL来源可能是不必要的。
#4
4
ILSpy can decompile an assmembly out to a tidy directory structure. Do this for each of your assemblies and you can use a diff tool of your choice to see what has changed.
ILSpy可以将一个组件分解为一个整洁的目录结构。对每个程序集都这样做,您可以使用自己选择的diff工具来查看发生了什么更改。
#5
4
This is sort of a duplicated question, to this one.
这是一个重复的问题。
As mentioned in the other one, there's a free & open source tool called BitDiffer. It's amazing, it can compare entire builds or single DLLs and it shows the namespace hierarchy to easily find what changed.
正如在另一篇文章中提到的,有一个免费的和开源的工具叫做bitdifferent。令人惊讶的是,它可以比较整个构建或单个dll,并显示名称空间层次结构,以便轻松查找更改的内容。
#6
1
I believe there is a Reflector addon for that at http://www.codeplex.com/reflectoraddins called diff. You can try that.
我相信在http://www.codeplex.com/reflectoraddins中有一个反射器addon,它叫diff,你可以试试。
#7
0
The diff addin for reflector is great! Ive been using it for years.
反射镜的diff插件很棒!我已经用了很多年了。
#8
0
I made a small tool specifically for comparing Assemblies in a certain way. I had two assemblies which were basically the same except the IL in the methods was slightly different and one had some NOPs spread throughout. The C# code was almost identical for them, but the IL was clearly quite different. I tried using ILDasm and comparing the generated output with TortoiseMerge/WinDiff, but it had so many false differences that it was useless. The NOPs really messed with the output since it changed branch addresses and such and basically produced a difference on every line of each method.
我做了一个小工具,专门用于以某种方式比较程序集。我有两个基本上相同的程序集除了方法中的IL有一点不同还有一个程序集有一些NOPs分布在整个程序集。c#代码对他们来说几乎是一样的,但是IL显然是完全不同的。我尝试使用ILDasm,并将生成的输出与玳瑁/WinDiff进行比较,但它有太多的错误差异,根本没用。由于它改变了分支地址,所以NOPs确实对输出进行了处理,并且基本上在每个方法的每一行上都产生了差异。
So, I built a small tool called ILDump. It's BSD licensed. It is capable of trimming out NOPs, using "smart" label renaming so that code that is the same, but shifted by a NOP, it won't be detected as a difference by Diff programs, and it also only prints out significant labels(ie, ones that are branched/switched to). It also can sort methods so that two assemblies that were "created" in a different way won't be caught as a difference.
所以我做了一个小工具叫ILDump。BSD许可。它可以通过使用“智能”标签重命名来删除NOPs,这样代码是相同的,但是通过NOP移动,它不会被Diff程序检测到差异,而且它也只打印出重要的标签(例如,被分支/切换到的)。它还可以对方法进行排序,以便以不同的方式“创建”的两个程序集不会被捕获为差异。
It's definitely not perfect, it doesn't handle any thing but dumping out each method's IL, and there is no hope of round tripping. The reason I created it was to make reading a method's IL easier(it's smart labeling makes it significantly easier to track branches), and so that I could run it through a program like TortoiseMerge or WinDiff and it not say there is a difference on every line of code.
它绝对不是完美的,它不处理任何事情,只处理掉每个方法的IL,而且不可能进行往返。我创建它的原因是为了使阅读一个方法的IL更容易(它的智能标记使它更容易跟踪分支),所以我可以运行它通过一个程序,如龟壳出现或WinDiff,它并不是说每一行代码都有差异。
#1
13
The tool NDepend offers many features to handle .NET code diff.
NDepend工具提供了许多处理。net代码差异的特性。
The panel Search by Change is dedicated to browse assemblies code diff:
更改面板搜索专用于浏览程序集代码diff:
Many code rules that constraint diff and evolution are proposed. They can be a good start to write your own ones or adapt them to your needs. For example look at the rule:
提出了许多约束diff和演进的代码规则。他们可以是一个很好的开始来写你自己的书或者根据你的需要改编它们。例如,看看规则:
Types that used to be 100% covered but not anymore
类型以前是100%覆盖,但现在不是
// <Name>Types that used to be 100% covered but not anymore</Name>
warnif count > 0
from t in JustMyCode.Types where
t.IsPresentInBothBuilds() &&
t.OlderVersion().PercentageCoverage == 100 &&
t.PercentageCoverage < 100
let culpritMethods = t.Methods.Where(m => m.PercentageCoverage < 100)
select new {t, t.PercentageCoverage, culpritMethods }
or also:
或者:
- API Breaking Changes: Methods
- API打破变化:方法
- Avoid making complex methods even more complex
- 避免使复杂的方法变得更加复杂
- Avoid decreasing code coverage by tests of types
- 避免通过类型测试降低代码覆盖率
- From now, all types added or refactored should respect basic quality principles
- 从现在开始,所有添加或重构的类型都应该遵循基本的质量原则
- Avoid transforming an immutable type into a mutable one
- 避免将不可变类型转换为可变类型
- Heuristic to find types moved from one namespace or assembly to another
- 启发式查找从一个名称空间或程序集移动到另一个名称空间或程序集的类型
To get started with NDepend compare capabilities, have a look at the documentation:
要开始使用NDepend比较功能,请查看文档:
-
Advanced Code Diff from within Visual Studio: explains how to use the NDepend build comparison features, in the context of Visual Studio and Visual NDepend standalone UI.
Visual Studio中的高级代码Diff:解释如何使用NDepend构建比较特性,在Visual Studio和Visual NDepend独立UI的上下文中。
-
Reporting Code Diff: explains how to use the NDepend build comparison features, in the context of reporting.
报告代码Diff:在报告的上下文中解释了如何使用NDepend构建比较特性。
Disclaimer: I work for NDepend
免责声明:我为NDepend工作
#2
5
You can use ILDasm
to generate il source from an assembly. IL source is basically a text file, so you can compare two il files using standard text diff tools. Interpreting the IL sources may not necessary, if you use the reported diffs as an indication where to look further.
您可以使用ILDasm从程序集中生成il源代码。IL source基本上是一个文本文件,所以您可以使用标准文本diff工具比较两个IL文件。如果您使用报告的差异作为进一步研究的指示,那么解释IL来源可能是不必要的。
#3
#4
4
ILSpy can decompile an assmembly out to a tidy directory structure. Do this for each of your assemblies and you can use a diff tool of your choice to see what has changed.
ILSpy可以将一个组件分解为一个整洁的目录结构。对每个程序集都这样做,您可以使用自己选择的diff工具来查看发生了什么更改。
#5
4
This is sort of a duplicated question, to this one.
这是一个重复的问题。
As mentioned in the other one, there's a free & open source tool called BitDiffer. It's amazing, it can compare entire builds or single DLLs and it shows the namespace hierarchy to easily find what changed.
正如在另一篇文章中提到的,有一个免费的和开源的工具叫做bitdifferent。令人惊讶的是,它可以比较整个构建或单个dll,并显示名称空间层次结构,以便轻松查找更改的内容。
#6
1
I believe there is a Reflector addon for that at http://www.codeplex.com/reflectoraddins called diff. You can try that.
我相信在http://www.codeplex.com/reflectoraddins中有一个反射器addon,它叫diff,你可以试试。
#7
0
The diff addin for reflector is great! Ive been using it for years.
反射镜的diff插件很棒!我已经用了很多年了。
#8
0
I made a small tool specifically for comparing Assemblies in a certain way. I had two assemblies which were basically the same except the IL in the methods was slightly different and one had some NOPs spread throughout. The C# code was almost identical for them, but the IL was clearly quite different. I tried using ILDasm and comparing the generated output with TortoiseMerge/WinDiff, but it had so many false differences that it was useless. The NOPs really messed with the output since it changed branch addresses and such and basically produced a difference on every line of each method.
我做了一个小工具,专门用于以某种方式比较程序集。我有两个基本上相同的程序集除了方法中的IL有一点不同还有一个程序集有一些NOPs分布在整个程序集。c#代码对他们来说几乎是一样的,但是IL显然是完全不同的。我尝试使用ILDasm,并将生成的输出与玳瑁/WinDiff进行比较,但它有太多的错误差异,根本没用。由于它改变了分支地址,所以NOPs确实对输出进行了处理,并且基本上在每个方法的每一行上都产生了差异。
So, I built a small tool called ILDump. It's BSD licensed. It is capable of trimming out NOPs, using "smart" label renaming so that code that is the same, but shifted by a NOP, it won't be detected as a difference by Diff programs, and it also only prints out significant labels(ie, ones that are branched/switched to). It also can sort methods so that two assemblies that were "created" in a different way won't be caught as a difference.
所以我做了一个小工具叫ILDump。BSD许可。它可以通过使用“智能”标签重命名来删除NOPs,这样代码是相同的,但是通过NOP移动,它不会被Diff程序检测到差异,而且它也只打印出重要的标签(例如,被分支/切换到的)。它还可以对方法进行排序,以便以不同的方式“创建”的两个程序集不会被捕获为差异。
It's definitely not perfect, it doesn't handle any thing but dumping out each method's IL, and there is no hope of round tripping. The reason I created it was to make reading a method's IL easier(it's smart labeling makes it significantly easier to track branches), and so that I could run it through a program like TortoiseMerge or WinDiff and it not say there is a difference on every line of code.
它绝对不是完美的,它不处理任何事情,只处理掉每个方法的IL,而且不可能进行往返。我创建它的原因是为了使阅读一个方法的IL更容易(它的智能标记使它更容易跟踪分支),所以我可以运行它通过一个程序,如龟壳出现或WinDiff,它并不是说每一行代码都有差异。