views:

37

answers:

2

Hello, I've got an executeable file, which I run for example from C:. The executable references some DLLs from another directory, let's say C:\MyDLLs. The problem is, that these referenced DLLs again depend on other DLLs, which are stored in another directory. Can I tell Visual Studio where to look for these missing DLLs? Thanks a lot!

+1  A: 

I've had this issue before and I created a post build script that copies all the needed DLLs into my executable's directory.

Something like: copy "$(ProjectDir)Resources\DLLs\yourDLL.dll" "$(TargetDir)yourDLL.dll"

KrisTrip
Thanks, but that would be hundreds of DLLs to copy. Other ideas?
iDog
http://msdn.microsoft.com/en-us/library/7d83bc18(VS.80).aspx That tells you the search path Windows uses to find DLLs. So, you could add the C:\DLLs directory to your PATH variable maybe. Only problem with that is of course it is lower on the search path list...so if it finds the DLL in one of the other places first, that will superceed it.
KrisTrip
I tried this already, curiously it doesn't work, I don't know why..
iDog
+3  A: 

You can reference assemblies outside of your app's assembly loading rules by setting these values in configuration. Here's a sample configuration file from this Microsoft KB article:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="MyAssembly2"  culture="neutral" publicKeyToken="307041694a995978"/>
            <codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

You use the <codeBase> element to tell your app where to look.

You have to make the assembly strong named (use the sn.exe tool) for this to work.

It's also useful to understand how the runtime resolves assembly references and maybe you can take advantage of that instead of going through all the hoops to use <codeBase>.

David Hoerster
thanks, I like your suggestion. Using System.Reflection.Assembly might be the answer for my question. I'll give a try. Thanks.
iDog