OK, so I have a .NET project that uses plugins. The plugins are implemented as Class Library (DLL) projects that each build in their own folders. The main project doesn't require the plugin DLLs to run, but if they are available, they are used for various optional functionality. Classes from the plugins are loaded by Type.GetType()
.
However, for my own purposes while testing the software, I'd like to be able to develop the plugins and the main application at the same time. I've created a "master" solution file that references all the projects, so I can set breakpoints and step across assembly boundaries. However, the problem is that the plugins build into their own directories, and so I have to somehow get the plugin DLL files somewhere where Type.GetType()
can find them.
Edit: to clarify, my code already enumerates DLL files in the same directory as the .exe and finds classes that match a given interface (using Assembly.LoadFile()
, Assembly.GetExportedTypes()
, and Type.IsAssignableFrom()
). Then the user selects plugins to enable, and I save those choices to the database using Type.AssemblyQualifiedName
. Finally, when I need to use functionality provided by the plugin, I use Type.GetType()
to load the plugin class. All of this works exactly as intended. It's just that when I build the app, I get a copy of the .exe without any plugins. I'm looking for a way to structure the project and solution files so that I can keep the main application and the plugin projects separate, while still being able to debug them together in Visual Studio. Does that make sense?
So far, these are the ideas I have:
Add references to the plugin projects from the main project.
This has the advantage that it will always work as intended in my debug environment, but will this cause problems when my app is deployed without its plugins? I checked using Dependency Walker and there doesn't seem to be any direct DLL dependency created by the project reference. Are there any hidden issues to know about here?Change all the plugin projects to build into the same target directory.
This would seem to work well enough, but it also muddies up my build tree, and it would make it harder to develop only one project without having other projects checked out (right now they are all sibling folders in Subversion).Add a post-build script to copy plugins to another directory.
This is actually what I'm doing at the moment, and it works well enough, but it seems very hackish and fragile. I'd like to switch to another approach.Find a way for
Type.GetType()
to search other directories for DLLs
This is similar to how I'd useLD_LIBRARY_PATH
on a Unix system. Obviously, I would only want to enable this for Debug builds, since in a Release mode this could cause lots of subtle problems on the user's system. But is this even possible? If so, how?
Interestingly, in this tutorial on the subject, it says:
The first thing to do is reference the class library we just created, and set the build output to the same directory.
That seems suboptimal to me. Is there a better way?