title: Namespaces and folder structures in c# solutions: how should folders on disk be organised?
body: <p>First off, let’s agree that namespace should match folder structure and that each language artefact should be in its own file.  </p>
  
  <p>(see <a href="https://stackoverflow.com/questions/4664/should-the-folders-in-a-solution-match-the-namespace">Should the folders in a solution match the namespace?</a> ).  </p>
  
  <p>The next question is how the folders should actually be organised on disk.<br>
  Suppose I have ClassC in the A.B.C namespace and ClassD in the A.B.C.D namespace.<br>
  Let’s also assume that each namespace is built into its own assembly (project) and that namespaces have dependencies from right to left as per accepted best practice (A.B.C.D can depend on A.B.C which can depend on A.B which can depend on A). I appreciate that each namespace doesn’t have to be in a separate assembly but in the general case we will have some namespaces in separate assemblies and my example illustrates that.</p>
  
  <p>I can see (at least) two ways to create the folder tree – which I’ll call “nested folders” and “flat folders”:  </p>
  
  <h2>1 - Nested folders:</h2>
  
  <p>A<br>
  --A.csproj<br>
  --B<br>
  ----A.B.csproj<br>
  ----C<br>
  ------A.B.C.csproj<br>
  ------classC.cs<br>
  ------D<br>
  --------A.B.C.D.csproj<br>
  --------classD.cs  </p>
  
  <p>OR</p>
  
  <h2>2 – Flat folders:</h2>
  
  <p>A<br>
  --A.csproj<br>
  A.B<br>
  --A.B.csproj<br>
  A.B.C<br>
  --A.B.C.csproj<br>
  --classC.cs<br>
  A.B.C.D<br>
  --A.B.C.D.csproj<br>
  --classD.cs  </p>
  
  <p>You will see I’ve made a few assumptions already:  </p>
  
  <ul>
  <li>Each project file has a fully qualified name (FQN) based on the namespace.</li>
  <li>Each class file uses a non-FQN</li>
  </ul>
  
  <p>Nested folders seems more natural (we all like hierarchies), but may be a bit harder to navigate in large solutions:</p>
  
  <p>When you look at your solution in VS, it shows a flat list of projects rather than a nested view. This looks more like “flat folders” so there may be merit in organising the folders on disk to match the view in VS.  </p>
  
  <p>If you look in each folder on disk you will see the folder artefacts for that project plus the sub folder for the namespace: taking C as an example:    </p>
  
  <p>C<br>
  --bin<br>
  --D<br>
  --obj<br>
  --Properties<br>
  --A.B.C.csproj<br>
  --classC.cs  </p>
  
  <p>Depending on D’s real name it may not be obvious that D is a namespace folder rather than an organisational folder in the C namespace.</p>
  
  <p>I know we’ve had folders and namespaces from day one in .NET (8 or 9 years ago) and Java before that, but, personally speaking, we don’t appear to have come to a consensus on best practice project organisation for large solutions. I’d be really interested to find out what you all think.  </p>
  
  <p>Thanks<br>
  Michael</p>