After tons of projects I have created, I wanted to share how I set the output directories of my projects and why I don’t follow the default output directories in Visual Studio templates. Let’s start by telling what I miss about the way the default templates work:
- When you have lots of projects, you have to dig into all project directories and the into the bin\Debug or bin\Release (depending on your build) to get the right output assemblies
- You cannot easily delete all the output files (no, clean solution never works for me)
I always strive for a clean directory structure, which is a must have if you have several projects inside a solution.
As you can see, it is all structured very, very nicely. If I am looking for specific part of the solution, I can simply find it, even when this solution contains over 30 (!) Visual Studio projects.
But not only the projects are structured. I have also made sure that all output directories are set up correctly. Take a look at the output directory of Catel:
As you can see, there is an output directory in the root of the solution. Then, the output directory contains a debug and a release folder. Then, these contain directories per target framework (NET35, NET40, NET45, SL4, SL5, WP7, WinRT, etc). Most people can skip this step because they are not writing projects that should target multiple target platforms. Last but not least, each project has its own directory inside the target framework directory. This way, I can easily grab the right assemblies in the right mode.
For example, if I am looking for all NET40 assemblies in debug mode, I can simply go to this folder:
Setting up the output directories
Setting up the output directories isn't hard, so I really don’t understand why so many people choose to go with the default settings of the Visual Studio templates. Following the steps below to set up the right output directories.
- First, make sure that all your source code (including the solution file) is located in the src folder, which is a subfolder of the root. This way, you can also include your documents (in the doc folder), the code snippets (in the snippets folder), etc.
- Open the solution and make sure to create solution directories to match the same directories as the directory structure. This way, it makes it way more easy to navigate through your code when the solution becomes more and more complex.
- Go to the properties of your project => Build tab and set the output path to this value:
You can see an example below (which contains NET35, which you can ignore if you don’t use different target frameworks for the project):
- Switch the Configuration to Release to make sure you also set the output directory for release builds:
From now on, you are the professional on your development team knowing exactly how to gather your assemblies.