Setting output directories of projects

by Geert 4. April 2012 21:05

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.

image

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:

image

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:

[ROOT]\output\debug\NET40\

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.

  1. 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.
  2. 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.
  3. Go to the properties of your project => Build tab and set the output path to this value:

    ..\..\output\debug\[MyProjectName]\

    You can see an example below (which contains NET35, which you can ignore if you don’t use different target frameworks for the project):

    image
  4. Switch the Configuration to Release to make sure you also set the output directory for release builds:

    image

From now on, you are the professional on your development team knowing exactly how to gather your assemblies.

Happy coding!

Tags: ,

C#

Sort Visual Studio 2008 Projects alphabetically inside Solution Folders

by Geert 9. January 2009 13:01

It is a known bug that Visual Studio does not sort projects alphabetically when the projects are located inside Solution Folders. Since I am working on pretty large solutions (more than 20 projects for 1 solution), and I like to order the projects via Solution Folders, this is a very irritating bug.

However, I accidently found the solution to this problem. Follow the steps below to sort your projects alphabetically inside Solution Folders.

  1. Right-click on a project and select rename (or simple select a project, wait 1 second, and click it again or press F2)
  2. Don’t change the name, simply select another project

Et voila, your projects are sorted like Visual Studio should do!

kick it on DotNetKicks.com

This blog article shows how to sort Visual Studio 2008 projects alphabetically inside Solution Folders

Tags:

General


About the Author

Geert van Horrik is an independent freelance software developer since January 1st, 2007. Since then he was been working on several projects from C++ to C# (WPF, Silverlight, ASP.NET, etc). Currently he loves to write his software using WPF (or Silverlight if WPF isn't an option).

Lately, Geert is spending a lot of time on Catel, a free open-source MVVM Framework for WPF and Silverlight. Actually, it's more than "just" an MVVM Framework, it's a complete application library!