Reputation: 10867
DLLs can be easily dynamically loaded from an application, by the following steps:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Then I call the CodeBase() method of the Assembly class to get the directory of where the app is. Next I would call Directory.GetFiles() to get a list of all files with the DLL extension, and then call Assembly.LoadFile().
I am trying to do the same thing but for a Windows service. When write the Windows Service Installer, I make sure all DLLs that would be dynamically loaded are also included. The problem is I don't know the equivalent of the steps above that I use for an application. Where is the service installed? Which directory?
Upvotes: 0
Views: 2030
Reputation: 1685
If the service is implemented in managed code, you can follow the pretty much the same steps as you've outlined in your question. That service is still a managed app and System.Reflection.Assembly.GetExecutingAssembly().Location
will provide the location of your assembly, which is your service. Then you can use GetDirectoryName
to find the service install directory.
Upvotes: 1
Reputation: 1352
I'm assuming that you are using a Installer Project template. You probably don't need to use reflection but instead look into implementing an Installer Class and during the commiting event verify that the assemblies that are required are in the target directory.
http://msdn.microsoft.com/en-us/library/system.configuration.install.installer.aspx
Upvotes: 0