.NET Core Project Structure

Understanding the default file and folder layout of a .NET Core application helps you navigate, organize, and maintain your codebase more efficiently.

Typical Directory Layout

MyApp/
├─ src/
│   ├─ MyApp/
│   │   ├─ Controllers/
│   │   ├─ Models/
│   │   ├─ Views/
│   │   ├─ Services/
│   │   ├─ Properties/
│   │   ├─ appsettings.json
│   │   ├─ Program.cs
│   │   └─ MyApp.csproj
├─ tests/
│   └─ MyApp.Tests/
│       ├─ MyApp.Tests.csproj
│       └─ UnitTest1.cs
├─ .gitignore
├─ README.md
└─ global.json (optional)

Key Files Explained

Customizing the Structure

While the layout above is a convention, you can adjust it to fit your project’s needs. The .csproj file controls what gets compiled, so moving files only requires updating the project file or using glob patterns:

<ItemGroup>
  <Compile Include="Features\**\*.cs" />
  <EmbeddedResource Include="Resources\**\*.*" />
</ItemGroup>

Best Practices

  1. Keep src and tests separate to avoid accidental production code deployment.
  2. Group related functionality (e.g., a feature module) in its own folder with sub‑folders for controllers, models, and services.
  3. Use global.json to lock the .NET SDK version across the team.
  4. Store secrets in user-secrets or environment variables, not in appsettings.json.
  5. Keep the .csproj tidy: use PackageReference and ProjectReference instead of manual assembly references.

On this page