An application folder can look quite crowded if you have some assemblies or 3rd party references in use.

Like in this image: proj_folder_before Wouldn’t it be much nicer to have it look like:proj_folder_after

When it comes to having dll-files somewhere else than in the “app-folder, things can get quite cumbersome.

Here’s how to achieve this:

Moving files into subfolder

There are multiple ways to achieve this.

One way is to add a solution folder with the desired name of the subfolder and add the assemblies / dependencies as files (best way is to add them as links) there with build action=none and copylocal=true. If you add assemblies there used as references as well, set the copylocal for the references to false.

Another way is to leave the dll’s where they are (just adding dependent dlls as files/links into the project’s root directory) and create a post-build event or (my preferred way) add an AfterBuild task to the project to move all *.dll files into the subfolder.

For the post-build event just edit the project’s properties and add the commands into the post-build in the Build Events.

For the preferred way, just edit the csproj file (unload the project, then right-click and edit, open in any text-editor or use the visual studio addon EditProj) and add the following code at the bottom:

<Target Name="AfterBuild">
	<ItemGroup>
		<FilesToMove Include="$(OutDir)*.dll" />
	</ItemGroup>
	<Move SourceFiles="@(FilesToMove)" DestinationFolder="$(OutDir)Libs" />
</Target>

This example code uses the folder “Libs” for the dlls. Feel free to adjust it to your needs.

Telling the application to search other directories for libraries

This is actually quite simple. The current way of doing this is to edit the app.config and adding the following code into the configuration:

<runtime>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<probing privatePath="Libs" />
	</assemblyBinding>
</runtime>

That’s it. With those two things you can have a “clean” application folder where all the assemblies or 3rd-party dependencies (like sqlite or sqlce dlls) are nicely stored in a subfolder

Leave a Reply

Your email address will not be published.

*