比较已编译的 .NET 程序集?
有没有什么好的程序可以与编译 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
比较 .NET 程序集的方法建议
商业:
免费:
现有的比较工具,例如 Beyond Compare(商业版) )可以通过特殊配置来做到这一点。 以下是如何为 Beyond Compare 执行此操作:
*.exe
或*.dll
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
)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:
*.exe
or*.dll
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
)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.
两种方式。
您可以使用经典工具进行 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..]
我只需比较同一 DLL 的两个修订版,它们具有相同的版本(我需要实现一个小修补程序,并在生产中部署 DLL,但我想确保没有其他更改泄漏到代码中)。 理想情况下,我希望 Assemby Diff 加载项向我显示差异,但它不起作用(它认为我正在将 DLL 与其自身进行比较)。 这就是我所做的:
这有点笨拙,但似乎有效。 不过,我希望 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:
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.
工具 NDepend 提供了许多功能来比较已编译的 .NET 程序集。
首先从 NDepend 起始页单击:比较代码库的 2 个版本。 这将允许您提供旧版本和新版本的程序集。
然后,在 NDepend 分析了较旧和较新的程序集之后,您可以使用面板按更改搜索。 它专门用于浏览程序集代码差异。 请注意:
另请注意,在屏幕截图中 CQLinq 代码查询 来浏览差异。
默认情况下会建议许多其他默认差异查询和规则,这将让您以智能方式浏览 .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.
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:
Notice also in the screenshot that a CQLinq code query is generated to browse the diff.
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.
另一种选择是 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.
这是一种跳出框框思考的方法,效果很好。
使用 dnSpy、dotPeek 或 JustDecompile 将新旧程序集转储到项目中。
创建一个新的 Git 存储库并首先提交旧的汇编代码。
在本地存储库文件夹中删除除“.git”之外的所有文件/文件夹,然后粘贴新的程序集文件。
要么提交新的更改并在 Github 上查看更改,要么使用 Fork 等 Git 查看器。 免费轻松进行代码比较。
Here's a thinking outside the box approach whcih works fine.
Dump your old and new assemblies with dnSpy, dotPeek or JustDecompile into projects.
Create a new Git repo and commit the old assembly code first.
In your local repo folder delete all the files/folders except for ".git" and paste the new assembly files.
Either commit the new changes and view changes on say Github or use a Git viewer like Fork. Easy code comparison for free.
Java 有一个很好的工具:语义差异实用程序
Java has a nice one: Semantic Diff Utilities