msbuild-antipatterns
Skill này làm gì
Skill này review các file MSBuild theo danh sách lỗi thường gặp, như dùng lệnh shell thay cho các task dựng sẵn. Skill dành cho lập trình viên muốn dọn dẹp các file project lộn xộn hoặc rủi ro.
Khi nào nên dùng
- ✓Khi bạn muốn review file .csproj, .props hoặc .targets để tìm lỗi build thường gặp.
- ✓Khi một file project có nhiều lệnh tùy chỉnh có thể thay bằng các bước build chuẩn.
- ✓Khi bạn muốn có danh sách cải tiến file build theo thứ tự ưu tiên trước khi phát hành.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/msbuild-antipatterns/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
“Review file project của tôi và cho biết thói quen MSBuild nào có rủi ro, kèm cách sửa cho từng cái.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent đọc file, đối chiếu từng phần với danh mục lỗi đã biết, rồi trả về các phát hiện được ưu tiên kèm cách sửa cho từng lỗi.
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.
MSBuild Anti-Pattern Catalog
A numbered catalog of common MSBuild anti-patterns. Each entry follows the format:
- Smell: What to look for
- Why it's bad: Impact on builds, maintainability, or correctness
- Fix: Concrete transformation
Use this catalog when scanning project files for improvements.
Review output contract
For review, audit, maintainability, or correctness-risk requests:
- Do not edit files unless the user explicitly asks for fixes.
- Return prioritized findings grounded in the supplied file, with impact and a targeted recommendation.
- Separate confirmed defects from conditional risks and already-correct patterns.
- Keep the final answer as the review; do not replace it with a terse summary of changes.
AP-01: <Exec> for Operations That Have Built-in Tasks
Smell: <Exec Command="mkdir ..." />, <Exec Command="copy ..." />, <Exec Command="del ..." />
Why it's bad: Built-in tasks are cross-platform, support incremental build, emit structured logging, and handle errors consistently. <Exec> is opaque to MSBuild.
<!-- BAD -->
<Target Name="PrepareOutput">
<Exec Command="mkdir $(OutputPath)logs" />
<Exec Command="copy config.json $(OutputPath)" />
<Exec Command="del $(IntermediateOutputPath)*.tmp" />
</Target>
<!-- GOOD -->
<Target Name="PrepareOutput">
<MakeDir Directories="$(OutputPath)logs" />
<Copy SourceFiles="config.json" DestinationFolder="$(OutputPath)" />
<Delete Files="@(TempFiles)" />
</Target>
Built-in task alternatives:
| Shell Command | MSBuild Task |
|---|---|
mkdir |
<MakeDir> |
copy / cp |
<Copy> |
del / rm |
<Delete> |
move / mv |
<Move> |
echo text > file |
<WriteLinesToFile> |
touch |
<Touch> |
xcopy /s |
<Copy> with item globs |
AP-02: Unquoted Condition Expressions
Smell: Condition="$(Foo) == Bar" — either side of a comparison is unquoted.
Why it's bad: If the property is empty or contains spaces/special characters, the condition evaluates incorrectly or throws a parse error. MSBuild requires single-quoted strings for reliable comparisons.
<!-- BAD -->
<PropertyGroup Condition="$(Configuration) == Release">
<Optimize>true</Optimize>
</PropertyGroup>
<!-- GOOD -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Optimize>true</Optimize>
</PropertyGroup>
Rule: Always quote both sides of == and != comparisons with single quotes.
AP-03: Hardcoded Absolute Paths
Smell: Paths like C:\tools\, D:\packages\, /usr/local/bin/ in project files.
Why it's bad: Breaks on other machines, CI environments, and other operating systems. Not relocatable.
<!-- BAD -->
<PropertyGroup>
<ToolPath>C:\tools\mytool\mytool.exe</ToolPath>
</PropertyGroup>
<Import Project="C:\repos\shared\common.props" />
<!-- GOOD -->
<PropertyGroup>
<ToolPath>$(MSBuildThisFileDirectory)tools\mytool\mytool.exe</ToolPath>
</PropertyGroup>
<Import Project="$(RepoRoot)eng\common.props" />
Preferred path properties:
| Property | Meaning |
|---|---|
$(MSBuildThisFileDirectory) |
Directory of the current .props/.targets file |
$(MSBuildProjectDirectory) |
Directory of the .csproj |
$([MSBuild]::GetDirectoryNameOfFileAbove(...)) |
Walk up to find a marker file |
$([MSBuild]::NormalizePath(...)) |
Combine and normalize path segments |
AP-04: Restating SDK Defaults
Smell: Properties set to values that the .NET SDK already provides by default.
Why it's bad: Adds noise, hides intentional overrides, and makes it harder to identify what's actually customized. When defaults change in newer SDKs, the redundant properties may silently pin old behavior.
<!-- BAD: All of these are already the default -->
<PropertyGroup>
<OutputType>Library</OutputType>
<EnableDefaultItems>true</EnableDefaultItems>
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
<RootNamespace>MyLib</RootNamespace> <!-- matches project name -->
<AssemblyName>MyLib</AssemblyName> <!-- matches project name -->
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<!-- GOOD: Only non-default values -->
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
AP-05: Manual File Listing in SDK-Style Projects
Smell: <Compile Include="File1.cs" />, `<Compile Inc
Câu hỏi thường gặp
Skill có tự động thay đổi project của tôi không?
Không. Review chỉ trả về phát hiện, trừ khi bạn yêu cầu áp dụng bản sửa.
Skill có dành cho việc chuyển đổi project cũ không?
Không. Việc chuyển project cũ sang định dạng mới do skill modernization đảm nhiệm.
Skill bao quát những lỗi nào?
Ví dụ gồm dùng Exec cho công việc mà các task MSBuild dựng sẵn xử lý tốt hơn.
Chi tiết
Mô tả gốc của tác giả
DO NOT INVOKE when the primary request explicitly asks to convert, migrate, modernize, or rewrite a legacy/old-style project to SDK style; use msbuild-modernization. Migration prompts often mention ToolsVersion, explicit Compile/Reference entries, packages.config, or Microsoft.CSharp.targets, but merely reviewing or auditing a file that contains those patterns remains in scope here. USE FOR broad review, audit, lint, or maintainability/correctness checks of project/build files, including custom targets; prioritized cross-cutting findings; discrete anti-patterns; F# ordering/FS0039; cross-platf
repo: dotnet/skills
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14604
- 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.