比较已编译的 .NET 程序集?

发布于 2024-07-14 17:29:19 字数 193 浏览 7 评论 0原文

有没有什么好的程序可以与编译 .NET 程序集进行比较?

例如,我有 HelloWorld.dll (1.0.0.0) 和 HelloWorld.dll (2.0.0.0),我想比较差异,我该怎么做?

我知道我可以使用 .NET Reflector 并使用 Assembly Diff 插件。 还有其他好的工具可以做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

迷鸟归林 2024-07-21 17:29:19

比较 .NET 程序集的方法建议

商业:

免费:


现有的比较工具,例如 Beyond Compare(商业版) )可以通过特殊配置来做到这一点。 以下是如何为 Beyond Compare 执行此操作:

  • 转至 工具选项
  • 单击新建..,选择“文本格式”,单击 确定
  • 为其命名(例如 EXE 或 DLL),并将掩码指定为 *.exe*.dll
  • 单击选项卡 转换并选择“外部程序(Unicode文件名)”
  • 在“加载”下,指定ildasm的路径并添加%s /OUT:%t /NOBARC:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\ildasm.exe %s /OUT:%t /NOBAR
  • (即 检查禁用编辑
  • 点击保存,然后关闭
  • 重新启动BC并打开两个exe文件进行比较,现在应该自动反编译为ilasm

您还可以向这种新格式添加语法突出显示。 我计划将语法文件发送给他们,以便可以共享

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.

悲欢浪云 2024-07-21 17:29:19

两种方式。

您可以使用经典工具进行 ILDASM 和 diff。

或者您可以使用 NDepends,但该功能需要付费。

[C# 臃肿的部分..]

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

旧梦荧光笔 2024-07-21 17:29:19

我只需比较同一 DLL 的两个修订版,它们具有相同的版本(我需要实现一个小修补程序,并在生产中部署 DLL,但我想确保没有其他更改泄漏到代码中)。 理想情况下,我希望 Assemby Diff 加载项向我显示差异,但它不起作用(它认为我正在将 DLL 与其自身进行比较)。 这就是我所做的:

  • 创建两个文件夹来保存反汇编的源文件。
  • 使用Reflector导出选项(从上下文菜单)从上一步创建的文件夹中的每个DLL生成源文件。
  • 使用免费的DiffMerge工具来比较两个目录; 这些工具向我展示了修改后的文件和差异。

这有点笨拙,但似乎有效。 不过,我希望 Assembly Diff 插件能够工作。

更新:最新版本的 Assembly Diff 插件应该解决比较同一程序集的两个版本的问题。 试一试。

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.

两人的回忆 2024-07-21 17:29:19

工具 NDepend 提供了许多功能来比较已编译的 .NET 程序集。

首先从 NDepend 起始页单击:比较代码库的 2 个版本。 这将允许您提供旧版本和新版本的程序集。

NDepend 比较2 代码库的版本

然后,在 NDepend 分析了较旧和较新的程序集之后,您可以使用面板按更改搜索。 它专门用于浏览程序集代码差异。 请注意:

  • 如果源代码可用,只需右键单击某个元素,然后单击比较源。 在 NDepend 选项中,您可以将任何代码差异工具(Visual Studio、Beyond Compare...)插入到 NDepend 中。
  • 如果您没有源代码,只有原始程序集,则可以选择“比较旧版本和新版本”选项使用 ILSpy 反汇编的版本。 支持 ILSpy v7.0 及更高版本。 此菜单适用于程序集、命名空间、类型和方法级别,您可以选择反编译为 C# 或 IL。

比较 . NET 程序集与 NDepend

另请注意,在屏幕截图中 CQLinq 代码查询 来浏览差异。

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

默认情况下会建议许多其他默认差异查询和规则,这将让您以智能方式浏览 .NET 代码差异。

免责声明:我是该工具的开发人员之一

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.

抠脚大汉 2024-07-21 17:29:19

另一种选择是 Microsoft 的 LibCheck

相当旧的控制台工具,用于获取公共 API 差异。 如果没有调试和重定向到更新的 .net 版本,我就无法运行。 然而,它给了我非常清晰的输出,我稍后会使用它。

这是一篇带有屏幕截图的文章

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.

左秋 2024-07-21 17:29:19

这是一种跳出框框思考的方法,效果很好。

  1. 使用 dnSpy、dotPeek 或 JustDecompile 将新旧程序集转储到项目中。

  2. 创建一个新的 Git 存储库并首先提交旧的汇编代码。

  3. 在本地存储库文件夹中删除除“.git”之外的所有文件/文件夹,然后粘贴新的程序集文件。

  4. 要么提交新的更改并在 Github 上查看更改,要么使用 Fork 等 Git 查看器。 免费轻松进行代码比较。

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.

盗琴音 2024-07-21 17:29:19

Java 有一个很好的工具:语义差异实用程序

Java has a nice one: Semantic Diff Utilities

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文