Adding a reference to a DLL in VS is no problem at all. However adding a reference via this method required the DLL to be in a specific path at compile and run time.
Now here is my problem: The DLL I want to reference is not guaranteed to be in the same spot on different machines. The location of the DLL depends on the user installing the program the DLL opens an API for. i.e. On machine A, the DLL is located at C:\SomeLocation\api.dll and on machine B, the DLL is located at F:\ThisAwesomeProgram\api.dll.
Can I add a reference to the DLL in VS to use it like any other DLL I added a reference to, and then (at runtime) change the path of the DLL and still use it?
Or do I need to use something like Assembly.LoadFrom
, and then call the methods via reflection and dynamic invocation?
Here is the workflow I intended to use:
- Add a reference to the DLL at compile time in Visual studio.
- Use the DLL as if the path would never change.
- Compile the program as usual.
- Start the program and then change the DLL location to the actual location (if different from the location known at compile time).
- Use the program parts the use the DLL as usual.