dimaba10000 wrote:
My original question was, if it was possible to get my executable application to check for .dll files in a specific folder on the users computer, to use that .dll file as a reference. Since I don't want to keep both .dll and .exe in the same folder.
You again misunderstood. There is not such thing as "check". Well, you can "check" by using something like
Directory.GetFiles
, but this can be useful if you want to load some assemblies during runtime and use reflection. I don't think this is what you want, you mentioned "reference" (and I'm not sure is you are ready).
When you reference assemblies, this is a different story: assemblies are referenced by the names of some PE files (your "DLLs") by name, or they can be referenced by strong names, and found in some directories (or in GAC). So, first and foremost, my best advice would be:
forget about your "I don't want to keep both .dll and .exe in the same folder" and… actually put them in the same folder. Pay attention on how your solution is built: even if your output paths are different for different projects (which is not very good; I always advise to put all output in the same directory; this is not done this way by default just because Visual Studio cannot do it automatically; and everything is designed to work immediately after your reference your projects by other projects), Visual Studio copies all the referenced DLLs where the application is.
I can see only
one case when you want to put some library assemblies in some separate directory
: when you have more than one product using those library assemblies; and when those products don't have to be installed at the same time, and when you don't want to put your libraries in GAC. In this, case, one of the possible techniques would be
using config file with assemblyBinding
element.
For example, let's assume you create some directories in different places, and some directory where your library files are. Suppose you put some application assembly, one of your products in some other directory (in my example shown below it could be the directory on the same level called "MyLibrary", but it could be any
relative path, relative to you application assembly file). You can add a configuration file to your assembly file; it it's name is "myApplication.exe", if should be "myApplication.exe.config". In this file you can write, for example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="..\MyLibrary"/>
</assemblyBinding>
</runtime>
</configuration>
It will allow "myApplication.exe" to search for assembly files referenced by name in "MyLibrary", more exactly, add this path in search.
—SA