How to save DLLs in a different folder when compiling in Visual Studio?

Correct answers were given earlier. I'll just mention that there is a nuget package for this called PrettyBin.

Install it on your startup project. DLLs and XMLs will go to a lib folder and you'll have a working example of how it's done, if you won't to customize.


There are 2 parts of your question:

How to configure solutions to build assemblies/EXE into folders of your choice - this is configured through properties of the project in VS (project properties -> build -> output path). Also value of check "copy local" property on each reference.

How to load assemblies files from non-default locations (i.e. from your ...\Libraries folder) - you need to make changes to your app.config file to add this non-default paths to assembly search location..

Link to Microsoft site no longer works, so summary from wayback machine: How to load an assembly at runtime that is located in a folder that is not the bin folder of the application:

Method 1: Install the assembly in the global assembly cache (GAC). The GAC is a computer-wide code cache where the common language runtime is installed. The GAC stores assemblies that you specifically designate to be shared by several applications.

Note You can only install strong-named assemblies in the GAC.

Method 2: Use an application configuration (.config) file with the tags A .config file contains the following settings:

• Settings that are specific to an application

• Settings that the common language runtime reads, such as the assembly binding policy settings and the remoting objects settings

• Settings that the application reads

The <codeBase> tags specify where the common language runtime can find an assembly. The common language runtime applies the settings of the <codeBase> tags from the .config file. The settings of the <codeBase> tags determine the version and the location of the assembly.

Method 3: Use the AssemblyResolve event The AssemblyResolve event fires whenever the common language runtime tries to bind to an assembly and fails. You can use the AddHandler method to add an event handler to the application that returns the correct assembly whenever the AssemblyResolve event fires.

The AssemblyResolve event handler must return an [Assembly] object, and the common language runtime must bind to this object. Typically, you can use the Assembly.LoadFrom method to load the assembly and then to return the object.