Our programs are running in an environment where it is bad to be wasteful of RAM. There are a large number of large 3rd-party packages we could use in our code that would make writing the code somewhat easier, but only a few of the methods in those packages are of interest to us, meaning most of the contents of the 3rd-party library .dll's would be code that, if loaded/compiled to RAM, would be a waste of memory.
Other places I have looked indicate clearly that for the main executable the JIT compiler compiles to machine code on a per-method basis as methods are actually used; and other places indicate clearly that assemblies are only loaded at the moment they are needed; but nothing I have seen yet explains the intersection of those two questions - Specifically, once a .dll assembly needs to be loaded mid-execution, does the CLR and JIT compiler perform optimizations so that only the parts of that .dll that actually need to be used are loaded into memory, or is the whole .dll loaded/compiled into memory at once?
If the answer is that only the methods actually called in the .dll are loaded/compiled, how can the runtime know which methods it needs to call without first loading the whole .dll into memory? Does it do two steps, one to load the whole .dll and examine it to find out which parts are needed, and then in a different step it takes the chunks of the .dll that are needed and compiles those, dropping the rest of the .dll out of memory?
How does this behavior differ if the .dll is managed code vs. unmanaged code?
How does this behavior differ if we use the "Produce Single File" publish setting in Visual Studio?