I'm using MEF
in a plugin based ASP.NET application. Wiring up a File System Watcher
with Container.Refresh()
any new plugin is loaded automatically upon being copied to the plugin folder.
The problem is when I want to delete or replace a loaded plugin. It is locked by w3wp
and cannot be deleted. I read about Shadow Copy
but cannot find a good example or article.
Try adding the plugin folder to AppDomainSetup.ShadowCopyDirectories. This property is a semicolon-seperated list of directories containing assemblies that should be loaded via shadow copies.
Normally you also need to set AppDomainSetup.ShadowCopyFiles to "true"
but I think this is already the default for ASP.NET appdomains.
However, be aware that loading a new version of a plugin will not magically unload the old version. The only way to do that is to unload the AppDomain containing it. Since this requires you to load plugins in a separate appdomain, this is probably more trouble than it is worth.
It is probably simpler, safer and more effective to just stop the service, update the DLLs, and restart.