Project Structure

codewithmukesh/dotnet-claude-kit/skills/project-structure

作者 codewithmukesh23300897f4d1無授權條款754 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 個月前更新

.NET solution and project structure conventions. Covers .slnx format, Directory.Build.props, Directory.Packages.props for central package management, global usings, and naming conventions. Load this skill when setting up a new solution, adding projects, configuring build properties, or when the user mentions "solution structure", ".slnx", "Directory.Build.props", "central package management", "Directory.Packages.props", "global usings", ".editorconfig", "project layout", or "naming conventions".

AI 產生的概覽

用於組織 .NET 解決方案的慣例:.slnx 格式、共用建置屬性、集中套件管理與命名規範。

功能
此技能提供 .NET 解決方案與專案結構的慣例。它說明 .slnx 解決方案格式、用於共用 MSBuild 設定的 Directory.Build.props、用於集中套件管理的 Directory.Packages.props、global.json 的 SDK 版本固定、全域 using 以及命名規範。它也列出反模式,並提供選擇專案配置的決策指南。它僅提供指引,不會產生檔案或指令碼。
適用情境
適用於建立新的 .NET 解決方案、新增專案、設定建置屬性時,或使用者提到解決方案結構、.slnx、Directory.Build.props、集中套件管理、Directory.Packages.props、全域 using、.editorconfig、專案配置或命名規範時。
執行需求
不需要任何工具、套件或認證;僅為說明性內容,不附帶指令碼。其指引適用於使用 MSBuild、NuGet 與 .NET SDK 的 .NET 專案。

Project Structure

Core Principles

  1. Central package management — Use Directory.Packages.props to manage NuGet package versions in one place. No version numbers in individual .csproj files.
  2. Shared build properties — Use Directory.Build.props for common settings (target framework, nullable, implicit usings). Don't repeat in every project.
  3. .slnx for solutions — The new XML-based solution format is cleaner and more merge-friendly than the legacy .sln format.
  4. src/tests separation — Source projects in src/, test projects in tests/. Clear boundary.

Patterns

Solution Layout

MyApp/├── MyApp.slnx                       # Solution file├── Directory.Build.props             # Shared MSBuild properties├── Directory.Packages.props          # Central package management├── .editorconfig                     # Code style rules├── .gitignore├── global.json                       # SDK version pinning├── src/│   ├── MyApp.Api/                    # Web API (entry point)│   │   ├── MyApp.Api.csproj│   │   ├── Program.cs│   │   └── Features/│   ├── MyApp.Domain/                 # Domain entities, value objects (optional)│   │   └── MyApp.Domain.csproj│   └── MyApp.Infrastructure/         # EF Core, external services (optional)│       └── MyApp.Infrastructure.csproj└── tests/    └── MyApp.Api.Tests/        └── MyApp.Api.Tests.csproj

Directory.Build.props

xml
<Project>  <PropertyGroup>    <TargetFramework>net10.0</TargetFramework>    <LangVersion>14</LangVersion>    <Nullable>enable</Nullable>    <ImplicitUsings>enable</ImplicitUsings>    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>  </PropertyGroup></Project>

Directory.Packages.props (Central Package Management)

xml
<Project>  <PropertyGroup>    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>  </PropertyGroup>
  <ItemGroup>    <!-- Versions below are illustrative — resolve the current stable versions         with `dotnet add package <name>` (no --version flag); see the packages rule -->    <!-- ASP.NET Core -->    <PackageVersion Include="Mediator.Abstractions" Version="3.0.0" />    <PackageVersion Include="Mediator.SourceGenerator" Version="3.0.0" />    <PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
    <!-- Data -->    <PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.10" />    <PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.10" />
    <!-- Observability -->    <PackageVersion Include="Serilog.AspNetCore" Version="10.0.0" />    <PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.17.0" />
    <!-- Testing -->    <PackageVersion Include="xunit.v3" Version="3.2.2" />    <PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.10" />    <PackageVersion Include="Testcontainers.PostgreSql" Version="4.13.0" />  </ItemGroup></Project>

Project File (.csproj) with Central Package Management

xml
<Project Sdk="Microsoft.NET.Sdk.Web">  <!-- No TargetFramework here — inherited from Directory.Build.props -->
  <ItemGroup>    <!-- No Version attribute — managed centrally -->    <PackageReference Include="Mediator.Abstractions" />    <PackageReference Include="Mediator.SourceGenerator" />    <PackageReference Include="FluentValidation.DependencyInjectionExtensions" />    <PackageReference Include="Microsoft.EntityFrameworkCore" />    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />    <PackageReference Include="Serilog.AspNetCore" />  </ItemGroup>
  <ItemGroup>    <ProjectReference Include="..\MyApp.Domain\MyApp.Domain.csproj" />    <ProjectReference Include="..\MyApp.Infrastructure\MyApp.Infrastructure.csproj" />  </ItemGroup></Project>

global.json (SDK Pinning)

json
{  "sdk": {    "version": "10.0.100",    "rollForward": "latestFeature"  }}

.slnx Solution Format

xml
<Solution>  <Folder Name="/src/">    <Project Path="src/MyApp.Api/MyApp.Api.csproj" />    <Project Path="src/MyApp.Domain/MyApp.Domain.csproj" />    <Project Path="src/MyApp.Infrastructure/MyApp.Infrastructure.csproj" />  </Folder>  <Folder Name="/tests/">    <Project Path="tests/MyApp.Api.Tests/MyApp.Api.Tests.csproj" />  </Folder></Solution>

Naming Conventions

ElementConventionExample
SolutionCompanyName.AppName or AppNameMyApp.slnx
ProjectAppName.LayerMyApp.Api, MyApp.Domain
NamespaceMatches folder pathMyApp.Api.Features.Orders
Feature folderPascalCase, pluralFeatures/Orders/
Test projectProjectName.TestsMyApp.Api.Tests

Anti-patterns

Don't Scatter Package Versions

xml
<!-- BAD — version in every .csproj, version drift --><PackageReference Include="Mediator.Abstractions" Version="2.0.0" />  <!-- in Project A --><PackageReference Include="Mediator.Abstractions" Version="3.0.0" />  <!-- in Project B -->
<!-- GOOD — central management, one version --><!-- Directory.Packages.props: <PackageVersion Include="Mediator.Abstractions" Version="3.0.0" /> --><!-- .csproj: <PackageReference Include="Mediator.Abstractions" /> -->

Don't Repeat Build Properties

xml
<!-- BAD — same properties in every .csproj --><PropertyGroup>  <TargetFramework>net10.0</TargetFramework>  <Nullable>enable</Nullable>  <ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<!-- GOOD — once in Directory.Build.props, inherited everywhere -->

Don't Mix Source and Test Projects

# BAD — tests mixed with sourcesrc/  MyApp.Api/  MyApp.Api.Tests/    # test project in src/
# GOOD — clear separationsrc/  MyApp.Api/tests/  MyApp.Api.Tests/

Decision Guide

ScenarioRecommendation
New solution.slnx format
Package version managementDirectory.Packages.props (central)
Shared build settingsDirectory.Build.props
SDK version pinningglobal.json
Common using directivesGlobal usings in Directory.Build.props
Small API (1-2 devs)Single project (MyApp.Api)
Medium API (3-5 devs)2-3 projects (Api, Domain, Infrastructure)
Large / modular appModule-per-project with shared Contracts

來源與署名

來源:codewithmukesh/dotnet-claude-kit位於skills/project-structure提交2330089

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 codewithmukesh/dotnet-claude-kit 的技能

Wrap Up

codewithmukesh

在 session 結束時把已完成工作、待辦事項與經驗寫入交接檔案,並在 session 開始時重新載入。

Productivity & Workflow7542 個月前更新

Workflow Mastery

codewithmukesh

Claude Code workflow mastery for .NET developers. Covers parallel execution with git worktrees, plan mode strategy, verification loops, auto-formatting hooks, permission setup for dotnet CLI, prompting techniques, subagent patterns, and context discipline — token budget management, MCP-first navigation, lazy loading, and subagent isolation — all adapted for the .NET ecosystem. Load this skill when setting up Claude Code for a .NET project, optimizing workflows, running parallel sessions, when context is running low or sessions feel sluggish, when exploring a large codebase efficiently, or when the user mentions "productivity", "workflow", "parallel", "worktree", "plan mode", "permissions", "hooks", "10x", "setup Claude Code", "speed up development", "context", "tokens", "budget", "running out of context", "too many files", or "large codebase". Inspired by tips from Boris Cherny (creator of Claude Code) and the Anthropic team.

待分類7542 個月前更新

Vertical Slice

codewithmukesh

指導 .NET 開發者以垂直切片架構組織應用程式,涵蓋功能資料夾、端點分組與處理常式模式。

Software Development7542 個月前更新

Testing

codewithmukesh

Testing strategy for .NET 10 applications. Covers xUnit v3, WebApplicationFactory for integration tests, Testcontainers for real database testing, Verify for snapshot testing, and the AAA pattern. Load this skill when writing tests, setting up test infrastructure, reviewing test coverage, or when the user mentions "test", "xUnit", "WebApplicationFactory", "Testcontainers", "integration test", "unit test", "bUnit", "snapshot test", "Verify", "test coverage", "AAA pattern", "WireMock", or "FakeTimeProvider".

待分類7542 個月前更新

Tdd

codewithmukesh

Guided test-driven development workflow for .NET 10 using xUnit v3, WebApplicationFactory, Testcontainers, and Verify snapshots. Follows the strict red-green-refactor cycle. Use when: "TDD", "test-driven", "let's TDD this", "red green refactor", "write the test first", or when building a feature with clear acceptance criteria.

待分類7542 個月前更新

Spec

codewithmukesh

透過結構化提問,把模糊的功能想法轉化為雙方確認並持久化的規格文件。

Productivity & Workflow7542 個月前更新