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

在会话结束时把已完成工作、待办任务与经验写入交接文件,并在会话开始时重新载入。

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个月前更新