Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active November 13, 2024 13:19
Show Gist options
  • Save davidfowl/ed7564297c61fe9ab814 to your computer and use it in GitHub Desktop.
Save davidfowl/ed7564297c61fe9ab814 to your computer and use it in GitHub Desktop.
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
  tests/
  .editorconfig
  .gitignore
  .gitattributes
  build.cmd
  build.sh
  LICENSE
  NuGet.Config
  README.md
  {solution}.sln
  • src - Main projects (the product code)
  • tests - Test projects
  • docs - Documentation stuff, markdown files, help files etc.
  • samples (optional) - Sample projects
  • lib - Things that can NEVER exist in a nuget package
  • artifacts - Build outputs go here. Doing a build.cmd/build.sh generates artifacts here (nupkgs, dlls, pdbs, etc.)
  • packages - NuGet packages
  • build - Build customizations (custom msbuild files/psake/fake/albacore/etc) scripts
  • build.cmd - Bootstrap the build for windows
  • build.sh - Bootstrap the build for *nix
  • global.json - ASP.NET vNext only

.gitignore

[Oo]bj/
[Bb]in/
.nuget/
_ReSharper.*
packages/
artifacts/
*.user
*.suo
*.userprefs
*DS_Store
*.sln.ide

There's probably more things that go in the ignore file.

  • Update: Added docs folder
  • Added README.md and LICENSE - Critical if you're OSS, if not ignore it
  • Renamed test to tests
  • Added lib for things that CANNOT exist in nuget packages
  • Removed NuGet.config for people using packet :)
  • Added global.json for ASP.NET vnext
  • Added .editorconfig file in the root (x-plat IDE settings)
  • Added NuGet.config back because people were confused about it missing
@fvilches17
Copy link

Hi @davidfowl thanks for sharing. Where would you put pipeline-related files? (e.g. azure-pipelines.yaml, resource-group.bicep, etc.)

@jedjohan
Copy link

Hi @davidfowl thanks for sharing. Where would you put pipeline-related files? (e.g. azure-pipelines.yaml, resource-group.bicep, etc.)

Sorry not David but a tip:

  • we put pipelines in /build (yaml pipes)
  • we put IaC (.bicep) in a folder named /infra

@fgimian
Copy link

fgimian commented Aug 19, 2021

I have a further thought too. I realise I'm in the absolute minority here, but I find it odd that we shorten source to src and libraries to lib yet there's no good reason to do this and we don't do this for any other folder. This really feels more historical than logical to me personally and doesn't make my OCD happy 😄

As such, I'm personally using source as my source folder ... does that make me a bit of an outcast? 😨

I personally put my azure-pipelines.yaml in the root folder but agree that it probably would be better in the build directory.

@fvilches17
Copy link

Hi @davidfowl thanks for sharing. Where would you put pipeline-related files? (e.g. azure-pipelines.yaml, resource-group.bicep, etc.)

Sorry not David but a tip:

  • we put pipelines in /build (yaml pipes)
  • we put IaC (.bicep) in a folder named /infra

👍

@TechWatching
Copy link

If your git repository also contains the frontend that consumes the dotnet API, where would you put the front code? The application code in /src and the tests code in /tests ?

@jedjohan
Copy link

jedjohan commented Nov 7, 2022

If your git repository also contains the frontend that consumes the dotnet API, where would you put the front code? The application code in /src and the tests code in /tests ?

Sorry not David again but an opinion:
1: keep it in a separate repo
2: if #1 not possible --> create folders below src: src/backend + src/frontend

@fvilches17
Copy link

Just a matter of preference of course, but since all ci-cd related files are used in an Azure/Azure DevOps context, I've started having a preference to putting yaml and bicep files in a folder called .azuredevops

I got the idea from GitHub actions' default root folder (.github)

@TechWatching
Copy link

If your git repository also contains the frontend that consumes the dotnet API, where would you put the front code? The application code in /src and the tests code in /tests ?

Sorry not David again but an opinion: 1: keep it in a separate repo 2: if #1 not possible --> create folders below src: src/backend + src/frontend

src/projectname.api and src/projectName.Front is what I did. But it felt weird to do the same for tests : tests/projectName.api.Tests tests/projectName.Front.Test

Just a matter of preference of course, but since all ci-cd related files are used in an Azure/Azure DevOps context, I've started having a preference to putting yaml and bicep files in a folder called .azuredevops

I got the idea from GitHub actions' default root folder (.github)

@fvilches17 I understand your point, but I am personally not a big fan of using dot folders that are platform specific. You are right, that's how github does it and if your ci-cd related files are only used in an Azure/Azure DevOps context, maybe it makes sense in your context.
However, I think that infrastructure files, ci files, or cd files should not be stored in a folder dependent on the platform (even if for github they don't really let you the choice).

Because maybe someday you will migrate from Azure DevOps to another platform, your application could be multi-cloud (with some resources in one cloud, and other in another) or even if it's an azure only application it coud use specific services (authentication, monitoring ...) outside Azure. Moreover, CI/CD files could contain other files than the Azure pipelines YAML files like scripts, configuration files, or even code files. That's why I prefer using an "infra" folder, a "build" or "pipelines" folder .... By the way, by default Azure Developer CLI (preview) uses an infra folder.

@mcintyre321
Copy link

If your git repository also contains the frontend that consumes the dotnet API, where would you put the front code? The application code in /src and the tests code in /tests ?

If UI and backend are worked on by the same team/organisation, they are the same app, and they should be versioned together (i.e. in the same repo) and deployed together.

@TechWatching
Copy link

If your git repository also contains the frontend that consumes the dotnet API, where would you put the front code? The application code in /src and the tests code in /tests ?

If UI and backend are worked on by the same team/organisation, they are the same app, and they should be versioned together (i.e. in the same repo) and deployed together.

I agree, I was just wondering what it means for the folder organization.

@mcintyre321
Copy link

mcintyre321 commented Nov 7, 2022 via email

@fvilches17
Copy link

thought I'd share,

this is the structure I follow for some projects. you can imagine that at root, besides the .azuredevops folder, there's src, test etc. folders

the name .azuredevops was chosen because back in Azure DevOps when you place a pull_request_template.md file in a folder with set name, then the repo's PR descriptions use the content of that file, pretty much used like a template for PR descriptions

however, the name can be anything of course. e.g. something generic like .devops

folder structure

@peteraritchie
Copy link

This thread makes me think there are several intents within the discussion. Is @davidfowl 's intent to outline a dotnet project for a monorepo, for deployment to custom infrastructure, for delivery of a package, etc.?

@agilenut
Copy link

This thread makes me think there are several intents within the discussion. Is @davidfowl 's intent to outline a dotnet project for a monorepo, for deployment to custom infrastructure, for delivery of a package, etc.?

My 2 cents:

I follow this structure when I'm not building a monorepo.

When I do build a monorepo, I wrap this structure in another set of folders at the root of the repository (one for each service, library, or app). But I might keep a few things like shared build pipelines, docs, and editorconfig in the root.

@tonidy
Copy link

tonidy commented Jun 4, 2023

@sharpninja @tiny-dancer I've created https://github.com/dotnet-template/project-layout, feel free to fork it and maybe contribute to it.

@aspeckt-112
Copy link

Could someone please explain to me the difference between putting nupkgs in the artefacts directory vs the packages directory?

@Layoric
Copy link

Layoric commented Jan 26, 2024

My understanding is the Artefacts is the output of your project, much could include NuGet packages, packages directory contains your projects dependencies.

@aspeckt-112
Copy link

Ahhh OK. For when a packages.config is being used. Not applicable to me and I think I was tunnel visioning past it.

Thanks, @Layoric

@oxygen
Copy link

oxygen commented Apr 12, 2024

@D3MaxT
Never distribute [the same] private cert to multiple distinct clients, even if you do it securely - you might as well drop encryption altogether.
For self signed certificates just generate them on the client machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment