C# Project Layout

17 Nov 2021

If you have developed any software in Java the chances are that you have come across Maven and the Standard Directory Layout. Some folks were not too keen on the layout, but Maven being an opinionated system itself, defined the convention. The convention stuck, and now you can find the code within any Java based project using Maven.

Microsoft Visual Studio

Let's take a look at the projects created by Visual Studio. The solution is created in the root of the selected directory. Next the project itself is created in a sub-directory and added to the solution. I think this is done to keep up the file structure similar to that of the Solution Explorer in the IDE. If you add another project then a new directory is created and the project is added to the solution. This makes sense in the IDE focused development environment that is Visual Studio.

JetBrains Rider

The JetBrains Rider product follows the Visual Studio layout pattern of a solution file in the root with the projects underneath. This makes sense in that their product is considered a Visual Studio IDE replacement. The layout will be familiar to developers picking up the IDE. Even on Linux they keep up appearances and continue with the traditional project structure.

.NET Runtime

If you look at Microsoft's projects in the .NET universe you get a different picture. The .NET Runtime project contains a src directory which in turn contains a further nested directory structure for projects. There is no solution file present in the root. However, you will find 250+ more solution files embedded in the directory tree. It's a big project. But the files' presence means they are using Visual Studio (as expected). If you look into a project directory you will find the solution file. However, this is not your ordinary Visual Studio directory structure because there is another src and a tests directory. The src directory contains the solution file. This structure looks similar to ~/runtime/src/libraries/Common/Microsoft.CSharp/src. That is hardly similar to the Visual Studio created default project layout. I am sure they have their reasons.

David Fowler, a prominent developer within .NET space, recommends following the solution in the root of the repository and a src directory for projects. Please see his Gist .NET project structure. This makes sense in that he is at Microsoft and either influenced or was influenced by their decisions for their public repositories.

Visual Studio Code

My point is that there is no standard. This comes to light if you happen to be developing .NET code on a non-Windows platform or if you are developing within Visual Studio Code. There the project structure is entirely up to you. That particular editor, and its usage of the command line tooling, enforces nothing. There is no directory standard layout. There is not even a suggested directory layout other than what is generated by Visual Studio.

Why do I care?

I can already hear you complaining: why you should care about this at all? The reality is that you should only care when working on a project with more than yourself. If you are working a personal project or temporary repository exploring some technology, please, do whatever you want. However, if you are working on a team (which is defined as you + 1) configuring the repositories should be a team effort. Without a Directory Standard Layout guideline for .NET development you can find yourself having multiple projects with differing layouts. I will grant you that is the worst case. The most likely case is that you are using the de facto standard Visual Studio layout. If Visual Studio Code is being used then I would suggest sticking with the Visual studio layout.

If you are working on a Microsoft project then the du jure standard appears to be something entirely different. Then I wish you Godspeed.

< back