验证我没有破坏公共类 API

发布于 2024-12-05 16:51:10 字数 231 浏览 2 评论 0原文

有人知道验证当前代码库不会更改现有公共 API 的好方法吗?我想将其作为持续集成过程的一部分来运行。

类似于集合:(

所有当前公共方法签名和公共类型名称的并集)与(所有先前的公共方法签名和公共类型名称)的交集

  • 应该等于(深度比较)所有先前的公共方法签名和公共类型名称

也许某个项目使用过 Mono.Cecil 或 NDepend 并且能够从命令行进行分析吗?

Does somebody know of a good way of verifying that the current code-base doesn't change existing public APIs? I would like to run this as a part of a continuous integration process.

Something like the set:

(the union of all current public method signatures and public type names) intersection with (all previous public method signatures and public type names)

  • should equal (deep compare) all previous public method signatures and public type names

Perhaps some project has used Mono.Cecil or NDepend and is capable of analysing this from the command line?

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

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

发布评论

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

评论(2

江心雾 2024-12-12 16:51:10

我不久前写了一篇关于如何避免 API 的博客文章NDepend 及其代码查询和规则功能发生了重大变化。 免责声明:我是该工具的开发人员之一

从那时起,NDepend 及其查询语言也不断发展。如果您下载 NDepend 试用版并分析您想要搜索 API 重大更改的代码库的两个版本,请在默认代码规则组 API 重大更改 中查看以下CQLinq 规则

执行此规则如下所示( NUnit v2.5.8 和 v2.5.3 之间的差异):

API 重大更改

您还会发现这些默认代码规则和相关查询:

I wrote a blog post a while ago about how to avoid API breaking change with NDepend and its code query and rule capabilities. Disclaimer: I am one of the developers of the tool

Since then, NDepend has evolved and its query language as well. If you download NDepend trial and analysis the two versions of your code base where you'd like to search for API breaking change, have a look in the default code rules group API Breaking Changes for the following CQLinq rules.

Executing this rule looks like for example (diff between NUnit v2.5.8 and v2.5.3):

API breaking changes

You'll find also these default code rules and queries relevant:

仅此而已 2024-12-12 16:51:10

corcompare 是 Mono 在内部使用的一个工具,用于将其 API 与 Microsoft .Net 实现进行比较。如果您想像 Mono 一样生成 HTML 报告,可以使用 corcompare在 github 上(可使用 Visual Studio 构建)。还有一个不错的 GUI 前端,名为 gui-compare,它使用相同的 Cecil 后端(UI 需要安装 gtk-sharp)。我以前用过它,它非常舒服 - 只需将它指向两个不同的 dll,就会弹出一个不错的比较窗口。另一方面,如果您想自动执行此检查,Corcompare 会生成 XML API 描述符。

这些工具验证方法描述符(包括参数名称,因为您可以在 C# 4 中按名称绑定参数)、可见性和属性(在程序集、类、方法和参数级别)。

There's corcompare, a tool that Mono uses internally to compare their API to the Microsoft .Net implementation. If you'd like to generate a HTML report like Mono does, corcompare is available on github (buildable with Visual Studio). There's also a nice GUI frontend called gui-compare that uses the same Cecil backend (UI requires gtk-sharp installed). I've used it before and it was very comfortable - just point it at two different dll's and a nice comparison window pops out. Corcompare, on the other hand, generates XML API descriptors, should you want to automate this check.

Those tools validate method descriptors (including parameter names, as you can bind parameters by name in C# 4), visibility and attributes (on assembly, class, method and parameter level).

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