Compare compiled .NET assemblies?
Asked Answered
A

7

55

Are there any good programs out there to compare to compile .NET assemblies?

For example I have HelloWorld.dll (1.0.0.0) and HelloWorld.dll (2.0.0.0), and I want to compare differences how can I do this?

I know I can use .NET Reflector and use the Assembly Diff plugin. Are there any other good tools out there to do this?

Aquanaut answered 16/3, 2009 at 22:46 Comment(4)
Just sheer binary differences? Or public interface differences?Instance
If you can use .NET Reflector with Assembly Diff, why do you need another tool? Is the plugin insufficient for your needs? If so, how?Confiture
@strager: in my experience, it doesn't workErkan
@strager: It does not let me compare two builds of the same assembly, at least when their version is the same.Lilian
B
55

Ways to Compare .NET Assemblies suggests

Commercial:

Free:


Existing compare tools like Beyond Compare (commercial) can do this by special configuration. Here's how to do this for Beyond Compare:

  • Go to ToolsOptions
  • Click New.., select "Text format", click OK
  • Give it a name (say, EXE, or DLL), and specify the mask as *.exe or *.dll
  • Click on tab Conversion and select "External program (Unicode filenames)"
  • Under "Loading", specify the path to ildasm and add %s /OUT:%t /NOBAR (i.e.: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\ildasm.exe %s /OUT:%t /NOBAR)
  • Make sure to check disable editing.
  • Click Save, then Close
  • Restart BC and open two exe files to compare, it should decompile into ilasm automatically now.

You can also add syntax highlighting to this new format. I plan to send the syntax file to them so that it'll become available to share.

Bots answered 16/3, 2009 at 23:0 Comment(5)
Just a note that Framework Design Studio is pretty useless. More like a book pusher that teaches the style and then eventually we all realise those guidelines are not the answer to anything. Reflector addin is about the only one that is free and good but under-developed.Wulf
I've spent 20 minutes today trying to use the reflector add in and I don't think that it works. I tried comparing 2 assemblies that were named the same thing in 2 different directories.Erkan
Telerik's JustDecompile lets you do this, but it's somewhat manual -- you use the "create project" method to generate source files for each (into different directories, obviously) then use something like Beyond Compare or DiffMerge etc to compare the source code.Smacker
@Erkan It appears that you can compare two assemblies, but they can't be "the same", as in using the same namespace and such... which makes this completely pointlessDidst
See more explanations about NDepend diff here ndepend.com/docs/code-diff-in-visual-studioWainscot
W
27

Two ways.

You could ILDASM and diff with classic tools.

Or you could use NDepends, which will cost for that feature.

[Piece to C# bloaters..]

Wulf answered 16/3, 2009 at 22:59 Comment(2)
+1, just ildasm both files, then diff the text output; you don't need expensive toosSweettalk
I love easy solutions like this.Tsarevitch
L
12

I just had to compare two revisions of the same DLL, which had the same version (I needed to implement a small hotfix, and deploy the DLL in production, but I wanted to make sure that no other changes leaked into code). Ideally, I would want the Assemby Diff add-in to show me the difference, but it does not work (it thinks that I'm comparing a DLL to itself). So this is what I did:

  • Created two folders to hold disassembled source files.
  • Used the Reflector's Export option (from context menu) to generate source files from each DLL in the folders created in previous step.
  • Used the free DiffMerge tool to compare two directories; the tools showed me the modified files and the difference.

It's a bit kludgy, but seems to work. I wish the Assembly Diff add-in worked, though.

UPDATE: The latest version of the Assembly Diff add-in is supposed to fix the issue of comparing two versions of the same assembly. Give it a try.

Lilian answered 20/7, 2009 at 22:9 Comment(2)
WindDiff that comes with Visual Studio is effective too.Tsarevitch
I assume you meant the WinDiff (one 'd') utility. It's OK, but DiffMerge is so much nicer.Lilian
W
7

The tool NDepend offers many features to compare compiled .NET assemblies.

First from the NDepend Start Page click: Compare 2 versions of a code base. This will let you provide older and newer versions of your assemblies.

NDepend Compare 2 Versions of a code base

Then after NDepend has analyzed both older and newer assemblies, you can use the panel Search by Change. It is dedicated to browse assemblies code diff. Notice that:

  • If source code is available, just right click an element and click Diff Source. In the NDepend options you can plug to NDepend any code diff tool (Visual Studio, Beyond Compare...)
  • If you don't have the source code and just only the raw assemblies, there is the option Compare older and newer version disassembled with ILSpy. ILSpy v7.0 and upper versions are supported. This menu works on assembly, namespace, type and method level and you can choose to decompile to C# or IL.

Compare .NET Assemblies with NDepend

Notice also in the screenshot that a CQLinq code query is generated to browse the diff.

from m in Application.Methods 
where m.CodeWasChanged() 
select new { m, m.NbLinesOfCode }

Many others default diff queries and rules are proposed by default, that will let you browse .NET code diff in a smart way.

Disclaimer: I am one of the developer of the tool.

Wainscot answered 28/8, 2010 at 14:15 Comment(3)
To those open source devs and people with shallow wallets, you do need to buy the professional edition for this feature, it's not in the trial.Threegaited
To those open source devs, we are always glad to sponsor a public OSS project with a free license, just contact us. Also the trial model has evolved and you can download now a 14-day fully functional trial (including diff features)Wainscot
@ChrisS Nowadays the NDepend trial is full-featured and what is explained is supported by trialWainscot
S
2

One more option is LibCheck from Microsoft.

Pretty old console tool for just getting public API diff. I could not run without debugging and retargeting to a more recent .net version. However, it gave me very clear output and I am going to use it later.

Here is an article with screenshots.

Sheath answered 8/8, 2015 at 11:43 Comment(0)
W
1

Here's a thinking outside the box approach whcih works fine.

  1. Dump your old and new assemblies with dnSpy, dotPeek or JustDecompile into projects.

  2. Create a new Git repo and commit the old assembly code first.

  3. In your local repo folder delete all the files/folders except for ".git" and paste the new assembly files.

  4. Either commit the new changes and view changes on say Github or use a Git viewer like Fork. Easy code comparison for free.

Washboard answered 7/3, 2022 at 1:50 Comment(1)
I found dumping with DnSpy into separate projects and then selecting the separate folders with WinMerge did exactly what I was looking for, while requiring more than one tool. Basically same as what you sayKierkegaardian
W
-11

Java has a nice one: Semantic Diff Utilities

Wendolynwendt answered 16/3, 2009 at 23:1 Comment(1)
Interesting, but not relevantTsarevitch

© 2022 - 2024 — McMap. All rights reserved.