我可以将 c# class 重定向到另一个 dll 吗?

Can I redirect a c# class to another dll?

这是我的问题。有一个带有核心库 core2.dll 的游戏引擎,里面有一个 class C。

这是一个 windows class,带有 c# 包装器。

我想主要使用 core2.dll 中的所有 classes 除了一个 class 我想使用以前版本库中的 class core1.dll

如果您尝试从 core2.dll 调用 class,它有一个 'deprecated error message'。

我认为 class 非常独立。 (假设它是一些数学函数)所以我的想法是在我的项目中同时包含 core2.dll 和 core1.dll,但不知何故只从 core1.dll 制作 class C。

关于如何(如果有的话)实现这一点有什么想法吗?

您需要为两个 dll 使用外部别名

这是一个例子: https://www.learningsomethingnew.com/how-to-use-two-versions-of-the-same-dll-in-the-same-project

如果您需要替换 core2.dll 中的部分代码,那么您可以使用 ildasm 对两者进行反编译,更改 core2.dll 中所需的部分,然后重新编译。

运行 x64_x86 Cross Tools Command Prompt for VS 2017 并执行

ildasm core1.dll /OUT=core1.il
ildasm core2.dll /OUT=core2.il


REM open il files with text editor, find classes in core1.il and replace them in core2.il 
REM note, that there might be no core2.res

ilasm core2.il /RESOURCE=core2.res /DLL

如果 dll 未签名,这绝对可以正常工作。更好的是 - 你 assemble 编写代码,这样 ilasm 将确保你的代码在运行时运行。 运行时间不兼容是绑定重定向的一个非常烦人的问题...

确保您没有违反任何许可和版权。