DEV Community

Cover image for .NET Project Folders Structure

.NET Project Folders Structure

Emanuele Bartolesi on June 24, 2022

We read very often how to have a good architecture for a .NET project, but I don't read very often how to structure the folders of the project. Y...
Collapse
 
jedjohan profile image
Johan Eriksson

Great structure, I have been, for a long time, following Fowlers old gist. And try to get everyone else to follow it :) The biggest issue is that people create the project in VS and if they let VS decide it will need some hands on.

gist.github.com/davidfowl/ed756429...

Collapse
 
kasuken profile image
Emanuele Bartolesi

Yes, it’s very similar and it inspired me a few years ago.
I didn’t invent nothing new 😀

By the way I have a PowerShell script to launch in the root folder when I create a new project to define the folders structure.
I think I should create VS extension.
What do you think?

Collapse
 
jedjohan profile image
Johan Eriksson

I´d say an extension could be nice. But then again, its kind of good to fix it manually, at least in the start, to learn how to handle it (edit the .sln and so on)

A question, I usually put my yaml pipelines (CI/CD) in a folder named /build, where do you put yours ?

Thread Thread
 
kasuken profile image
Emanuele Bartolesi

yes, in the build folder.
I see a lot of people with a folder called "deploy" for the same reason.

Collapse
 
stphnwlsh profile image
Stephen Walsh

I don't have a fixed solution structure but have tried a few different things. What you've got there is pretty similar, I go back and forth on needing all the extra folders

github.com/stphnwlsh/CleanMinimalA...

I build and test is Dockerfile so there's no need for build and am not concerned about artifacts because I allow external systems like Codecov to own that data.

If I was working on a bigger project for an enterprise I'd add the extras as needed.

Love that you're thinking about this, structure is important!!

Collapse
 
kaylumah profile image
Max Hamulyák

We use a fixed project structure all the time.
To the extend that when giving a training one of the trainees said oh I recognize this from project X I know what to do.

It makes it a lot easier to move devs between projects

Collapse
 
vaso profile image
Vaclav Elias

Nice overview, thanks!

Collapse
 
polterguy profile image
Thomas Hansen

A great folder structure is the foundation for your project's structure. If you mess up your folders you mess up your project :)

Collapse
 
stphnwlsh profile image
Stephen Walsh

Every thought about turning this into a dotnet new template? Would be pretty slick.

Collapse
 
kasuken profile image
Emanuele Bartolesi

good idea

Collapse
 
fredrikhr profile image
Fredrik Høisæther Rasch

In addition I have a standardised Directory.Build.props file which also enforces repo-root per-project/per-TFM obj/bin folders. It also adds the repo-root LICENSE file into nuget packages you produce and adds standard dev-only packages I always use (e.g. SourceLink).

Collapse
 
fredrikhr profile image
Fredrik Høisæther Rasch

Nowadays, I never write cmd or shell scripts. Since the release of PowerShell Core, I have now replaced shell scripts with PowerShell for cross-platform compat. Also, build agents on GitHub and AzDevOps come with PowerShell pre-installed.
The reason for this is to avoid duplication.

Collapse
 
erdtsieck profile image
Anne Erdtsieck

Wouldn't visual studio keep suggesting to put new projects in the root folder, given the solution is in that folder?