简体   繁体   English

比较编译的 .NET 组件?

[英]Compare compiled .NET assemblies?

Are there any good programs out there to compare to compile .NET assemblies?有没有什么好的程序可以比较编译 .NET 程序集?

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?例如,我有 HelloWorld.dll (1.0.0.0) 和 HelloWorld.dll (2.0.0.0),我想比较差异我该怎么做?

I know I can use .NET Reflector and use the Assembly Diff plugin.我知道我可以使用 .NET Reflector 并使用 Assembly Diff 插件。 Are there any other good tools out there to do this?有没有其他好的工具可以做到这一点?

Ways to Compare .NET Assemblies suggests 比较 .NET 组件的方法建议

Commercial:商业的:

Free:自由的:


Existing compare tools like Beyond Compare (commercial) can do this by special configuration. Beyond Compare(商业)等现有的比较工具可以通过特殊配置来做到这一点。 Here's how to do this for Beyond Compare:以下是如何为 Beyond Compare 执行此操作:

  • Go to ToolsOptions Go 到工具选项
  • Click New.. , select "Text format", click OK点击新建.. ,select“文本格式”,点击确定
  • Give it a name (say, EXE, or DLL), and specify the mask as *.exe or *.dll给它一个名字(比如,EXE 或 DLL),并将掩码指定为*.exe*.dll
  • Click on tab Conversion and select "External program (Unicode filenames)"单击选项卡转换和 select“外部程序(Unicode 文件名)”
  • Under "Loading", specify the path to ildasm and add %s /OUT:%t /NOBAR (ie: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\ildasm.exe %s /OUT:%t /NOBAR )在“加载”下,指定ildasm的路径并添加%s /OUT:%t /NOBAR (即: 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.重启BC,打开两个exe文件比较一下,现在应该会自动反编译成ilasm了。

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 .我计划将语法文件发送给他们, 以便共享

Two ways.两种方式。

You could ILDASM and diff with classic tools.您可以使用经典工具进行 ILDASM 和 diff。

Or you could use NDepends, which will cost for that feature.或者您可以使用 NDepends,这将花费该功能。

[Piece to C# bloaters..] [一块 C# 肿块..]

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).我只需要比较相同 DLL 的两个修订版,它们具有相同的版本(我需要实施一个小修补程序,并在生产中部署 DLL,但我想确保没有其他更改泄漏到代码中)。 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).理想情况下,我希望 Assemby Diff 加载项向我展示差异,但它不起作用(它认为我正在将 DLL 与自身进行比较)。 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.使用Reflector导出选项(从上下文菜单中)从上一步创建的文件夹中的每个 DLL 生成源文件。
  • Used the free DiffMerge tool to compare two directories;使用免费的DiffMerge工具比较两个目录; 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.不过,我希望 Assembly Diff 插件能够正常工作。

UPDATE: The latest version of the Assembly Diff add-in is supposed to fix the issue of comparing two versions of the same assembly.更新:Assembly Diff 插件的最新版本应该解决比较同一程序集的两个版本的问题。 Give it a try.试试看。

The tool NDepend offers many features to handle .NET code diff. NDepend工具提供了许多功能来处理 .NET 代码差异。 Disclaimer: I am one of the developer of the tool .免责声明:我是该工具的开发人员之一

The panel Search by Change is dedicated to browse assemblies code diff. Search by Change面板专用于浏览程序集代码差异。 Notice that:请注意:

  • You can plug to NDepend any code diff tool used by the menu Compare older and newer version of source file您可以插入 NDepend 菜单使用的任何代码差异工具比较源文件的旧版本和新版本
  • If you don't have the source code, only the raw assemblies, there is the option Compare older and newer version disassembled with Reflector如果您没有源代码,只有原始程序集,则可以选择使用 Reflector 反汇编比较旧和新版本

NDepend 按差异面板搜索

Notice also in the screenshot that a CQLinq code query is generated to browse the diff.另请注意,在屏幕截图中生成了一个CQLinq 代码查询来浏览差异。

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.默认情况下提出了许多其他默认差异查询和规则,这将使您以智能的方式浏览 .NET 代码差异。

One more option is LibCheck from Microsoft.另一种选择是来自 Microsoft 的LibCheck

Pretty old console tool for just getting public API diff.用于公开 API 差异的相当旧的控制台工具。 I could not run without debugging and retargeting to a more recent .net version.如果没有调试和重新定位到更新的 .net 版本,我就无法运行。 However, it gave me very clear output and I am going to use it later.但是,它给了我非常清楚的 output ,我将在以后使用它。

Here is an article with screenshots.这是一篇带有屏幕截图的文章。

Java has a nice one: Semantic Diff Utilities Java 有一个不错的: Semantic Diff Utilities

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问已编译.NET程序集的MSIL代码? - How to access the MSIL code of compiled .NET assemblies? 编译.NET程序集时,名称中包含x__的类是什么? - When .NET assemblies are compiled, what are the classes that have x__ in their names? 在 .NET Core 和 Xamarin 中使用从 IL 编译的程序集 - Using assemblies compiled from IL with .NET Core & Xamarin 如何在已编译的.NET程序集中使用Matlab对象? - How can I use Matlab objects in compiled .NET assemblies? 检查已编译程序集的内容 - Inspecting contents of compiled assemblies 加载动态编译的程序集的符号 - Loading symbols for dynamically compiled assemblies 使用MsBuild 4.0编译的程序集是否与仅具有.NET 3.5的计算机兼容? - Are assemblies compiled with MsBuild 4.0 compatible with computers which have only .NET 3.5? 如何在平台无关的路径中和已编译的程序集文件夹外部创建log4net日志文件 - How to create log4net log file in a platform independent path and outside of compiled assemblies folder 为什么使用ttinclude而不是编译的程序集? - Why use ttinclude instead of compiled assemblies? 在动态编译的代码中引用动态加载的程序集 - Referencing dynamically loaded assemblies in dynamically compiled code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM