Whenever I have to clean up my machine in preparation for changing my hardware or an OS refresh, I always find some forgotten gems in the process. Here’s one that I’m throwing up onto my blog for prosperity sake.
Every so often I have a project with lots of assemblies and dependencies which results in a deployment folder that can be daunting to the uninitiated. It would be great if the deployment folder had the exe and the config file and all the other dependencies were hidden in subfolders.
Here’s an example of how to do that.
- First, create two projects. Shell is an exe and Dependency is a ClassLibrary
- Change the Build folder of Shell to point to “..\AssemblyOutput”
- Change the Build folder of Dependency to point to “..\AssemblyOutput\modules”
- In the Shell project, add a reference to the Dependency project
- In the Shell’s references, set the CopyLocal property of the Dependency reference to “False”. If you don’t do this, the assembly will be copied to the root folder of the Shell’s output folder.
- Add the following to the Shell’s app config:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <!-- Probing path is relative to the executable. Multiple values are supported (bin;bin2;modules;modules\subfolder)--> <probing privatePath="modules"/> </assemblyBinding> </runtime> </configuration>
Now when you run the project, the first time the code comes across a reference to a type inside the Dependency assembly, it will load the assembly in the modules folder.