Monday, July 02, 2007

Naming Conventions for Project and Solution Folders

Small Solution Structures

If the project space is small I'll just name the folder and solution to match the fully-qualified namespace.

Folder
c:\FrogsBrain.MyFancyPants

Solution
c:\FrogsBrain.MyFancyPants\FrogsBrain.MyFancyPants.sln

Namespace
FrogsBrain.MyFancyPants

Larger Solution Structures

If the solution directory tree is very deep or there are many projects are under the root namespace I will break the solution folders up to remove redundant uses of the root name.

Folder
c:\FrogsBrain\MyFancyPants

Solution
c:\FrogsBrain\MyFancyPants\MyFancyPants.sln

Namespace
FrogsBrain.MyFancyPants

This will help keep to avoid errors when a path can get too long and wreak havoc with some source control tools.

Project Structures

The project names will follow suit, leaving out the name of the solution.

Folder
c:\FrogsBrain.MyFancyPants\Library
OR
c:\FrogsBrain\MyFancyPants\Library

Project
c:\FrogsBrain.MyFancyPants\Library\Library.csproj
OR
c:\FrogsBrain\MyFancyPants\Library\Library.csproj

Namespace
FrogsBrain.MyFancyPants.Library

Output
FrogsBrain.MyFancyPants.Library.dll

The exception is that the project output will be the fully-qualified name of the project. This makes identifying the assembly easier and prevent collision of names like Library.dll.

Folders Not Divided By Namespace

Inside of projects I try to follow the same structure but if a folder is not to be included in a namespace or I want to group some files without changing the namespace structure I will create a folder with a "_" prefix.

Project
c:\FrogsBrain\MyFancyPants\Library\Library.csproj

Folders
c:\FrogsBrain\MyFancyPants\Library\_build
c:\FrogsBrain\MyFancyPants\Library\_configuration
c:\FrogsBrain\MyFancyPants\Library\_documentation
c:\FrogsBrain\MyFancyPants\Library\_contracts\ISomeView.cs
c:\FrogsBrain\MyFancyPants\Library\_service\ISomeService.cs

Namespace
FrogsBrain.MyFancyPants.Library

Output
FrogsBrain.MyFancyPants.Library.dll

All files inside of "_" prefix folders are considered to be in the same namespace as their parent folder.




I've tried variations of these structures but will be implementing this as the standard structure for all projects I am responsible for in the future. It's the cleanest and easiest to manage layout I've worked with and has grown from experimentation over a couple years. So, if you look at some of my code and it doesn't already follow this pattern it will eventually.

Submit this story to DotNetKicks

0comments: