问题
Is there a way to load an assembly from disk and execute code in it without getting the file locked on disk? I never understood why it is necessary to lock the file since the code will be loaded in RAM and JIT-compiled?
回答1:
It's possible, you can use Assembly.Load(byte[]) to load an assembly as well. That assembly doesn't have a "loading context", you can load it repeatedly. Managing this is however not easy, you're bound to find out.
回答2:
What you are looking for is called shadow copying. You have to create a new AppDomain and provide an AppDomainSetup instance with the property ShadowCopyFiles set to the string true.
This application domain will copy the assemblies to a temporary location before loading them. See the MSDN for more details.
来源:https://stackoverflow.com/questions/2886397/load-and-execute-code-from-an-assembly-without-locking-the-file