C# 在构建期间重命名命名空间
我正在寻找一种在构建过程中在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经想通了。有两种解决方案:
ILRepack
ILRepack 有选项
Internalize
和RenameInternalized
。Internalize
会将合并程序集的公共修饰符更改为内部,而RenameInternalized
会将一些随机 guid 附加到这些类型名称。所有用法也都被正确重命名。程序集重写器
https://github.com/nullean/ assembly-rewriter
用于重写程序集的 Dotnet 工具并重命名命名空间。它仅限于与程序集文件名相同的根命名空间。
I have figured it out. There are two solutions:
ILRepack
ILRepack has options
Internalize
andRenameInternalized
.Internalize
will change public modifiers to internal for merged assemblies whileRenameInternalized
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.