Compare compiled .NET assemblies?
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 Tools → Options
- 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 intoilasm
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.
.NET Assembly Diff / Compare Tool - What's available?
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
Is there a way to diff two .NET executables?
Yes using NDepend you can diff between two .Net assemblies. Although even compiling exactly the same source twice will not generate exactly the same assemblies.
Compare 2 versions of a .NET assembly?
The tool NDepend offers many features to handle .NET code diff. Disclaimer: I am one of the developer of the tool.
The panel Search by Change is dedicated to browse assemblies code diff. Notice that:
- You can plug to NDepend any code diff tool used by the menu Compare older and newer version of source file
- If you don't have the source code, only the raw assemblies, there is the option Compare older and newer version disassembled with Reflector
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
Is there a way to compare 2 version of a compiled ASP.NET app to see if they are the same?
You can compare binary files from Beyond Compare. Just do a folder compare and when you have your folders selected, select the files you want to compare and hit the Compare Contents button to display the dialog below:
When you hit start, it will compare each file and tell you if they are the same or not. File that have this icon between them are not the same as each other.
Compare Two DLL's
I would recommend to disassemble two libraries with the Reflector (right click on the assembly -> Export) and then compare directories generated with some merging tool, like WinMerge.
Tool to compare .dlls and disassemble the differences?
Reflector has a Diff tool. Note: Reflector is now paid software.
Note: the Diff tool is not available anymore. You can still download it via Softpedia and use it with older versions of Reflector (from around 2010). On later versions it doesn't work anymore.
DLL comparison to confirm If same source code is used
There's no way to tell this.
Not only are no two compiled DLL's the same because of the MVID and other properties that differ each time you compile: two assemblies containing the same number of methods doesn't tell anything:
- The implementation of the methods can differ (e.g. v1's
Foo()
method containsreturn true
, while v2'sFoo()
containsreturn false
) - Different source code can yield the same IL.
It seems like you have an entirely different problem you want to solve, like educating your team and using continuous integration to share assemblies that are compiled on a build server. If you can explain why you want to make sure two DLLs were compiled from the same source, perhaps some better answers can be given.
Related Topics
How to Make Backgroundworker Return an Object
Intersect with a Custom Iequalitycomparer Using Linq
Is There a Complete Iequatable Implementation Reference
How to Apply a General Rule for Remapping All Property Names When Serializing with JSON.Net
What Are the Default Schedulers for Each Observable Operator
Reference a .Net Core Library in a .Net 4.6 Project
Importing Excel into a Datatable Quickly
How to Generate Unique Public and Private Key via Rsa
Dynamically Switch Wcf Web Service Reference Url Path Through Config File
How to Play a Sound in an ASP.NET Web Page
How to Specify Mapping Rule When Names of Properties Differ
How to Test Your Request.Querystring[] Variables
The Bare Minimum Needed to Write a Msmq Sample Application
How to Convert a System.Io.Stream to a Windows.Storage.Streams.Irandomaccessstream