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.
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.
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)
- Quick ability to determine if two assemblies are equivalent at the code level (not just the API's)
- 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)
The tool NDepend offers many features to handle .NET code diff.
The panel Search by Change is dedicated to browse assemblies code 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:
Types that used to be 100% covered but not anymore
// <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
- 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:
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.
Reporting Code Diff: explains how to use the NDepend build comparison features, in the context of reporting.
Disclaimer: I work for NDepend
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.
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.
Try these:
I believe there is a Reflector addon for that at http://www.codeplex.com/reflectoraddins called diff. You can try that.
The diff addin for reflector is great! Ive been using it for years.
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.
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.
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.
来源:https://stackoverflow.com/questions/1280252/net-assembly-diff-compare-tool-whats-available