C# 在构建期间重命名命名空间

发布于 2025-01-20 12:46:36 字数 616 浏览 2 评论 0原文

我正在寻找一种在构建过程中在3-RD组装中重命名名称空间的方法(并在用户代码中使用语句对应)。我搜索了Fody的织布工,但没有找到这样的东西。有一个对Ilrepack的拉动请求,可以做确切的事情,但似乎是陈旧的,并且不是通过CI: https://github.com/gluck/il-repack/pull/268

让我们说我有两个项目A和B,都被刺激了,B都对APPACK依赖。因为我不想要在引用BI AM将A与Ilrepack合并为B中并在此内化的A时,将消费者锁定在A上的特定版本,但是尽管在B中被内化了,但是当消费者在他的项目C中使用A和B的类别中还是类型的歧义。

Nest Package(Elasticsearch客户端 https://github.com/elasticsearch-net-net-net-net-net )使用newtonsoft.json软件包完成了确切的操作。

I am looking for a way to rename namespaces in an 3-rd party assembly during build process (and corresponding using statements in user code). I searched through fody's weavers but haven't found such thing. There is a pull request to ILRepack that does exact thing but it seems to be stale and not passing CI: https://github.com/gluck/il-repack/pull/268

Lets say I have two projects, A and B, both are nugetized and B has package dependency on A. Since I do not want to lock consumer on specific version on A when referencing B I am merging A into B with ILRepack and internalize A there, but despite A being internalized in B there is a type ambiguity on classes from A when consumer uses A and B in his project C.

NEST package (elasticsearch client https://github.com/elastic/elasticsearch-net) has done the exact thing with Newtonsoft.Json package.

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

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

发布评论

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

评论(1

我三岁 2025-01-27 12:46:36

我已经想通了。有两种解决方案:

ILRepack

ILRepack 有选项 InternalizeRenameInternalizedInternalize 会将合并程序集的公共修饰符更改为内部,而 RenameInternalized 会将一些随机 guid 附加到这些类型名称。所有用法也都被正确重命名。

程序集重写器

https://github.com/nullean/ assembly-rewriter

用于重写程序集的 Dotnet 工具并重命名命名空间。它仅限于与程序集文件名相同的根命名空间。

I have figured it out. There are two solutions:

ILRepack

ILRepack has options Internalize and RenameInternalized. Internalize will change public modifiers to internal for merged assemblies while RenameInternalized will append some random guids to these type names. All usages are also correctly renamed.

Assembly Rewriter

https://github.com/nullean/assembly-rewriter

Dotnet tool that rewrites assemblies and rename namespaces. It is limited to root namespace that is the same as assembly file name.

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