Set path to referenced .dll files
-
Thursday, September 20, 2012 2:54 AM
Basically, I have a C# winform app that is referencing two .dll files. When I build the app, it places the .dll files in the same directory as the .exe files
Example:
bin\Release\MyApp.exe
bin\Release\ALib.dll
bin\Release\BLib.dll
I wand the two dll files in a folder in that directory
Something like:
bin\Release\_MyApp\ALib.dll
bin\Release\_MyApp\BLib.dll
bin\Release\MyApp.exe
How can I accomplish this?
All Replies
-
Thursday, September 20, 2012 3:38 AM
You can change the "build output" settings, but you will have to use the AssemblyResolveHandler to open these assemblies in the correct folder.
See this link for details: .NET Assemblies and Visual Studio Projects
See section "Organize the development environment" towards the end of the article.
Dan Randolph - My Code Samples List
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Friday, September 28, 2012 9:55 AM
-
Thursday, September 20, 2012 2:54 PMModerator
By default the Copy to Output is set to true which puts the binaries in the same directory as the EXE. This is most likely what you want as the CLR can then load the assemblies. In rare cases you might want to locate the binaries elsewhere. However you're adding a lot of work onto yourself.
First, if the binaries are not one's you build, then you're going to have to move the files to the appropriate directory. This will require a build event which means you're going to have to write the commands to create the directory and copy the binaries from their source location.
Next you'll need to set the Copy to Output to false so the binaries are not copied. Note that this is generally only done for shared or GAC assemblies so you're introducing something that can be hard to debug if it goes wrong. You'll want to make sure it is well documented and that everybody on your team is aware of this diversion from the norm.
Finally you'll need to let the CLR know that the assemblies are available. By default the CLR is going to look in the app's root directory for non-strongly named assemblies. Since the path you specified is under the app root directory you can modify your config file to include the _MyApp directory as a private directory for finding assemblies. The CLR will then search the subfolder as well. The config settings are documented here: http://msdn.microsoft.com/en-us/library/823z9h8w(v=vs.100).aspx. Note that when you run into trouble with this scenario and you post questions about it in the forums make it very clear what you're doing because this is a non-standard setup and will impact the solutions you are provided.
Alternatively if it is only a couple of assemblies you could also use a binding redirect but that is probably overkill. You could also use the assemblyresolve event but that is also probably overkill for this simple scenario.
Michael Taylor - 9/20/2012
http://msmvps.com/blogs/p3net
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Friday, September 28, 2012 9:56 AM

