.NET Assembly Diff / Compare Tool - What's available? [closed]
Asked Answered
C

8

26

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)

Cosimo answered 14/8, 2009 at 21:11 Comment(0)
N
13

The tool NDepend offers many features to handle .NET code diff.

The panel Search by Change is dedicated to browse assemblies code diff:

enter image description here


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:


To get started with NDepend compare capabilities, have a look at the documentation:

Disclaimer: I work for NDepend

Nudnik answered 15/8, 2009 at 8:59 Comment(0)
D
6

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.

Dachia answered 22/1, 2013 at 18:35 Comment(1)
Using this technique with a directory-tree differencing tool such as WinMerge or Araxis Merge has showen to be very usefulCharette
L
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.

Lahr answered 8/4, 2011 at 19:9 Comment(0)
R
5

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.

Rolo answered 20/5, 2015 at 13:37 Comment(1)
Very good tool. Can't believe it had no useful clicks so farDisability
M
4

Try these:

Metz answered 14/8, 2009 at 21:16 Comment(2)
Thanks for the suggestions; NDepend is on our 'to-buy' list for next year, but their Compare tools aren't available in the trials. Do you know if it does code-level diffs? Framework Design Studio is API-level, and I've got libcheck but haven't actually tested it--so I'll give it a shot right now :)Cosimo
I did mess about with NDepend a while back, but never got into it too deep. I was impressed with it, but I don't know about the code-level diff I'm afraid.Metz
G
1

I believe there is a Reflector addon for that at http://www.codeplex.com/reflectoraddins called diff. You can try that.

Goldshlag answered 14/8, 2009 at 22:37 Comment(1)
I've got it, and it does exactly what I want--but is only good for comparing a single method at a time. I mentioned this pitfall in line 1 of my question :)Cosimo
N
0

The diff addin for reflector is great! Ive been using it for years.

Naashom answered 13/1, 2010 at 23:10 Comment(1)
I like it as well for individual comparisons, but it doesn't scale when you need a diff report for a full assembly with several hundred methods, or for several hundred assemblies with a total of thousands of methods :-DCosimo
C
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.

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.

Chafer answered 4/9, 2012 at 0:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.