Can I split a .net DLL without having to recompile

2019-05-18 07:51发布

问题:

I have a C# project that builds into a single DLL with two classes, ClassA and ClassB. For project management reasons, I'd like to move ClassB into a separate DLL, leaving the original DLL with ClassA only.

The problem is that I have other DLLs (also compiled from C#) that reference ClassA and ClassB in their original DLL. ClassA is fine but calling ClassB ends up with a TypeLoadException.

(I could recompile all of those other DLLs with their new project references, but I'd rather not do that, again for project management reasons.)

Is there a way I could deploy my new split DLLs and have the other DLLs continue to work? Or, do I really need to bite the proverbial bullet and plan to deploy new versions of all these files?

回答1:

You achieve this using Type forwarding. This enables moving a type to another assembly. In the original assembly, you add a TypeForwardedTo-attribute to signal that the type has been moved.

See this link for detailed information.