'Visual Studio: How to tell exe where to look for dll's?

I have a .lib included in my project (Linker->Input->Additional Dependencies) that makes my .exe build require a corresponding .dll to be provided with the .exe. Naturally, I would put the .dll in the same folder as .exe and that works fine, but I want to have only the .exe in the main folder and all other files, along with this .dll, in a subdirectory. How do I make the .exe look for it in that directory?

Just for clarification, I don't need VS to look for the .dll, but the program(.exe), after it has been built. Sorry if this was already asked, but I just can't find the right answer.



Solution 1:[1]

Temporary solution: Apparently this is much harder than I thought, just like Hans said. However, I have stumbled upon a neat trick which can somewhat make it look like this, and that is to create an internal .exe and put it into a subfolder with the .dll's, while it is just executed from a main .exe. ShellExecute command can be used to do this. Anyway, if anyone know how to actually do the real thing, please write it down :)

Solution 2:[2]

As @Hans Passant commented, I've solved it in my project (C#/WPF/vs2019) by editing app.config to:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="External"/>
    </assemblyBinding>
  </runtime>
</configuration>

Note that my output dir tree is like:

bin/
|--<myapp>.exe
|--External
    |--nuget1.dll
    |--nuget2.dll

You can specify multiple paths by delimiting them with semicolon.

For more information, see MS Docs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vladivarius
Solution 2 Hurry Zeng