Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare compiled .NET assemblies?

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?

like image 616
Danny G Avatar asked Mar 16 '09 22:03

Danny G


People also ask

Can you compare DLL files?

You can even compare entire directories. This is of course if you just need to know if they're the same, since it won't show you any code.

What are the different types of .NET assemblies?

There are three types of assemblies: Private assemblies. Shared assemblies. Satellite assemblies.

What is JustAssembly?

JustAssembly is a lightweight . NET assembly diff and analysis tool built on top of the Telerik JustDecompile Engine. As opposed to just comparing signatures, it produces a diff on all assembly contents including the code of the methods.


5 Answers

Ways to Compare .NET Assemblies suggests

Commercial:

  • NDepend

Free:

  • JustAssembly (only shows differences in API)
  • BitDiffer (same)
  • Reflector Diff Add-in (which you've already discovered, but not available anymore)

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.

like image 74
Daniel LeCheminant Avatar answered Sep 30 '22 07:09

Daniel LeCheminant


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..]

like image 20
rama-jka toti Avatar answered Oct 02 '22 07:10

rama-jka toti


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.

like image 37
Alek Davis Avatar answered Sep 30 '22 07:09

Alek Davis


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.

  • Types that used to be 100% covered but not anymore
  • 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

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

like image 29
Patrick from NDepend team Avatar answered Sep 30 '22 07:09

Patrick from NDepend team


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.

like image 23
Eugene Avatar answered Oct 02 '22 07:10

Eugene