directory-build-organization
Skill này làm gì
Skill này hướng dẫn đặt các thiết lập build, target và phiên bản package chung vào file Directory.Build dùng chung để các project không phải lặp lại. Skill dành cho đội có nhiều project .NET cùng lặp lại một thiết lập.
Khi nào nên dùng
- ✓Khi nhiều project .NET lặp lại cùng thiết lập build hoặc phiên bản package.
- ✓Khi bạn muốn tập trung chính sách build dùng chung trên toàn solution.
- ✓Khi thiết lập Directory.Build hiện có gặp lỗi import hoặc phân lớp.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/directory-build-organization/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Solution của tôi có mười project với cùng thiết lập build được chép vào từng project. Chuyển các thiết lập dùng chung vào một chỗ.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent kiểm tra mỗi thiết lập riêng của project nằm ở đâu, đề xuất bố cục với file Directory.Build.props và targets, và giải thích mỗi file nên chứa những thiết lập nào.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Organizing Build Infrastructure with Directory.Build Files
Intent control
- For "should we", "how should we organize", "recommend", "advise", or review requests, inspect the actual project files and return a proposed layout only. Do not create or edit files unless the user explicitly asks to apply, move, centralize, or clean up the configuration.
- Before summarizing, verify which project retains each project-specific property, item, or target. Name the actual file; do not infer it from sibling names.
- Recommend a verification command only after discovering a real
.sln,.slnx,.proj, or project file at that path. If no repo-root entry point exists, give commands for the discovered projects or state that the entry point was not found. - Every advice response must explain that
Microsoft.Common.propssearches upward from each project and automatically imports the nearestDirectory.Build.propsearly; project values can then override shared defaults. Explain the equivalent lateMicrosoft.Common.targetsimport when recommendingDirectory.Build.targets.
Directory.Build.props vs Directory.Build.targets
Understanding which file to use is critical. They differ in when they are imported during evaluation:
Evaluation order:
Microsoft.Common.props imports Directory.Build.props early
→ project body and package/project imports evaluate
→ Microsoft.Common.targets imports Directory.Build.targets late
Use .props for |
Use .targets for |
|---|---|
| Setting property defaults | Custom build targets |
| Common item definitions | Late-bound property overrides |
| Properties projects can override | Post-build steps |
| Assembly/package metadata | Conditional logic on final values |
| Analyzer PackageReferences | Targets that depend on SDK-defined properties |
Rule of thumb: Properties and items go in .props. Custom targets and late-bound logic go in .targets.
Because .props is imported before the project file, the project can override any value set there. Because .targets is imported after everything, it gets the final say—but projects cannot override .targets values.
⚠️ Critical: TargetFramework Availability in .props vs .targets
Property conditions on $(TargetFramework) in .props files silently fail for single-targeting projects — the property is empty during .props evaluation. Move TFM-conditional properties to .targets instead. ItemGroup and Target conditions are not affected.
See targetframework-props-pitfall.md for the full explanation.
Directory.Build.props
Good candidates: language settings, assembly/package metadata, build warnings, code analysis, common analyzers.
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Company>Contoso</Company>
<Authors>Contoso Engineering</Authors>
</PropertyGroup>
</Project>
Do NOT put here: project-specific TFMs, project-specific PackageReferences, targets/build logic, or properties depending on SDK-defined values (not available during .props evaluation).
Directory.Build.targets
Good candidates: custom build targets, late-bound property overrides (values depending on SDK properties), post-build validation.
<Project>
<Target Name="ValidateProjectSettings" BeforeTargets="Build">
<Error Text="All libraries must target netstandard2.0 or higher"
Condition="'$(OutputType)' == 'Library' AND '$(TargetFramework)' == 'net472'" />
</Target>
<PropertyGroup>
<!-- DocumentationFile depends on OutputPath, which is set by the SDK -->
<DocumentationFile Condition="'$(IsPackable)' == 'true'">$(OutputPath)$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
</Project>
Directory.Packages.props (Central Package Management)
Central Package Management (CPM) provides a single source of truth for all NuGet package versions. See https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management for details.
Enable CPM in Directory.Packages.props at the repo root:
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup
Câu hỏi thường gặp
Props hay targets?
File props được import sớm và project có thể ghi đè, còn file targets được import muộn.
Skill có thay đổi file mà không hỏi không?
Với yêu cầu tư vấn, skill chỉ đề xuất bố cục. Nó thay đổi file khi bạn yêu cầu áp dụng.
Skill có bao quát quản lý phiên bản package tập trung không?
Có. Skill bao quát việc tập trung phiên bản package trong một file dùng chung.
Chi tiết
Mô tả gốc của tác giả
USE ONLY for (1) two or more projects with repeated MSBuild policy, targets, or package versions, or (2) an existing Directory.Build.props/targets/rsp hierarchy with an import, placement, or layering defect. A one-project repo without an existing Directory.Build file is outside scope; do not load this skill. Covers centralizing shared policy and targets, Directory.Packages.props across projects, parent hierarchy/import structure, props-versus-targets placement, and folder/project exceptions. An existing hierarchy defect remains in scope when only one project is affected. For property value or
repo: dotnet/skills
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14597
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-custom-agent
5.8kGiúp agent của bạn tạo file custom agent cho VS Code, với các tool, hướng dẫn và handoff riêng sang agent khác.
create-skill
5.8kGiúp agent của bạn tạo một agent skill mới với tên hợp lệ, mô tả kích hoạt rõ ràng và file SKILL.md đúng tiêu chuẩn.
csharp-scripts
5.8kGiúp agent của bạn chạy một chương trình C# nhỏ dưới dạng một file duy nhất bằng công cụ dòng lệnh .NET, không cần tạo project đầy đủ.
dotnet-pinvoke
5.8kGiúp agent của bạn gọi các thư viện native C hoặc C++ từ .NET đúng cách, gồm khai báo chữ ký, xử lý chuỗi, bộ nhớ và safe handle.
Skill tương tự
openclaw-update
394kGiúp agent của bạn cập nhật OpenClaw Gateway đang có, chọn cách cập nhật phù hợp với cách cài đặt và giữ phiên làm việc của bạn hoạt động.
diagnose-gateway
394kGiúp agent của bạn tìm hiểu vì sao OpenClaw Gateway bị lỗi bằng cách kiểm tra cài đặt, kênh và cổng mà không thay đổi gì.
crabbox-apps
394kGiúp agent của bạn mở và chạy một app trên máy đám mây tạm thời, rồi hiển thị giao diện của nó trong thanh bên của chat.