Normally you have to put all the .dll files your application uses in the same location as the .exe file. I would like to keep the libraries in some other, dedicated folder and just show my app where to look for them (by some path in app.config or something like that). How do I do this?
You can use the <probing>
element in app.config to specify where to look for dependencies. I believe this will have to be a directory under the location of the exe though, not in an arbitrary place on disk.
See "Locating the assembly through codebases or probing" for more information on how this hangs together.
You could use Reflection to load in the dll from a specified path and then access all the classes and methods therein, although it would be a lot of hard work! You would also lose the benefits of intellisense, however it is possible, see:
Consider also the GAC - its purpose is to hold assemblies ;)
Actually there is some other way that suits my needs best. Using reflection (assebly.loadfrom) is unpleasant and would require a lot of changes in my code. But you could add a handler to appDomain.AssemblyResolve event and show the location of requested assembly if it is not found.
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
return Assembly.LoadFrom("C:\\TestAssembly.dll");
}
I advise you to either use the GAC or distribute all dependent DLLs with the EXE. Otherwise you risk getting obscure versioning bugs or applications that stop working suddenly and what-not.
Also, don't forget that if your shared code is on a network share you'll probably need to modify each computers security settings anyway.
Regards