.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
- Program.cs – Entry point for the application. Configures host, services, and middleware.
- appsettings.json – Central configuration file for connection strings, app settings, and logging.
- MyApp.csproj – MSBuild project file that lists package references, target frameworks, and build options.
- Controllers/ – MVC/Web API controllers handling HTTP requests.
- Models/ – Domain entities, DTOs, and data structures.
- Views/ – Razor views for MVC applications.
- Services/ – Business logic and dependency‑injected services.
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
- Keep
src
andtests
separate to avoid accidental production code deployment. - Group related functionality (e.g., a feature module) in its own folder with sub‑folders for controllers, models, and services.
- Use
global.json
to lock the .NET SDK version across the team. - Store secrets in
user-secrets
or environment variables, not inappsettings.json
. - Keep the
.csproj
tidy: usePackageReference
andProjectReference
instead of manual assembly references.