item-management

Diagnoses and fixes MSBuild item group patterns including batching, transforms, and metadata semantics.

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill item-management-patrick-rex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: item-management
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-msbuild/skills/item-management
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill item-management-patrick-rex

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? MSBuild item groups are a common source of build bugs: duplicate file warnings from SDK globbing, targets running more times than expected due to cross-product batching, and Include vs Update misuse that silently fails to modify items. This Skill provides canonical patterns from Microsoft.Common.CurrentVersion.targets to diagnose and correct these issues in .csproj files. ## Core Features & Use Cases - Include/Remove/Update Semantics: Clarifies when to add items, subtract items via set operations, or modify metadata on existing items without re-adding them. - Batching and Transforms: Explains %(Metadata) batching at target and task level, per-item filtering with Condition, and @(Item->'expression') transforms for path mapping. - Pitfall Remediation: Fixes cross-product batching (O(N×M) executions), CS2002 duplicate file warnings, missing FileWrites registration for clean support, and generated files polluting the source tree instead of IntermediateOutputPath. - Use Case: A target that zips outputs runs 12 times instead of 3 because it references %(Metadata) from two item groups; this Skill identifies the cross-product and rewrites it to batch on one group while reading the other as a property. ## Quick Start Ask the assistant to review your .csproj item groups for batching mistakes, duplicate globbing, or Include versus Update misuse and apply the canonical fixes.

Frequently Asked Questions about item-management

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix CS2002 duplicate file warnings in a .csproj?

CS2002 warnings come from SDK globbing adding a file that is also explicitly Included. Remove the redundant explicit Include, or use Update instead of Include to modify metadata on items the SDK already globbed.

What is the difference between Include, Remove, and Update in MSBuild?

Include adds new items with identity and metadata, Remove subtracts items matching a pattern or clears a group, and Update modifies metadata on items already in the group. Update never adds items, so it silently does nothing on missing items.

Why does my MSBuild target run more times than expected?

Referencing %(Metadata) from two different item groups in one expression creates a cross-product, causing O(N×M) executions. Batch on one group's metadata and reference the other group through a property instead.

How does MSBuild item batching with %(Metadata) work?

When %(Metadata) appears in target Outputs, Condition, or task parameters, MSBuild batches execution once per unique metadata value. Target-level batching uses Outputs, while task-level batching occurs inside task parameters like DestinationFiles.

When should generated files go to IntermediateOutputPath instead of the source tree?

Generated files should always be written to $(IntermediateOutputPath) (obj/), never the source directory. Source-tree generation pollutes version control and can cause duplicate compilation when SDK globs pick up the generated files.

Why are my generated files not deleted by dotnet clean?

Files created during a target must be added to the @(FileWrites) item group for dotnet clean to remove them. Register every generated file in FileWrites within the target that produces it.