target-authoring
Canonical patterns for writing custom MSBuild targets. USE FOR: diagnosing and fixing custom target authoring anti-patterns; broken SDK target chains across files (e.g., Directory.Build.targets silently redefining SDK targets); targets that replace CompileDependsOn instead of extending it with $(CompileDependsOn); query targets returning stale results from Outputs vs Returns misuse; missing Inputs/Outputs causing unnecessary rebuilds; missing FileWrites registration. Covers DependsOnTargets vs BeforeTargets vs AfterTargets, the Build→CoreBuild three-level pattern, and the $(XxxDependsOn) chain
npx skills add dotnet/skills --skill target-authoring --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Custom Target Authoring Patterns Canonical patterns from `Microsoft.Common.CurrentVersion.targets` in the MSBuild repository. ## The Three-Level Target Chain Every major entry point (Build, Rebuild, Clean) delegates to a **property** listing its dependencies, which chains through Before → Core → After: ```xml <PropertyGroup> <BuildDependsOn> BeforeBuild; CoreBuild; AfterBuild </BuildDependsOn> </PropertyGroup> <Target Name="Build" Condition=" '$(_InvalidConfigurationWarning)' != 'true' " DependsOnTargets="$(BuildDependsOn)" Returns="@(TargetPathWithTargetPlatformMoniker)" /> <!-- Empty extensibility targets — users override these --> <Target Name="BeforeBuild" /> <Target Name="AfterBuild" /> ``` `CoreBuild` delegates to `$(CoreBuildDependsOn)` and includes error handlers: ```xml <Target Name="CoreBuild" DependsOnTargets="$(CoreBuildDependsOn)"> <OnError ExecuteTargets="_TimeStampAfterCompile;PostBuildEvent" Condition="'$(RunPostBuildEvent)' == 'Always'" /> <OnError ExecuteTargets="_CleanRecordFileWrites" /> </Target> ``` ### Rules - Delegate to a property (`DependsOnTargets="$(MyTargetDependsOn)"`), not hardcoded targets. - `OnError` goes inside the orchestrating target to ensure
- The Three-Level Target Chain
- Rules
- Chain Extension — Append, Never Overwrite
- DependsOnTargets vs BeforeTargets vs AfterTargets
- Returns vs Outputs
- Target Naming Conventions
- Complete Custom Target Template
- Common Pitfalls
What does the target-authoring skill do?
Canonical patterns for writing custom MSBuild targets. USE FOR: diagnosing and fixing custom target authoring anti-patterns; broken SDK target chains across files (e.g., Directory.Build.targets silently redefining SDK targets); targets that replace CompileDependsOn instead of extending it with $(CompileDependsOn); query targets returning stale results from Outputs vs Returns misuse; missing Inputs/Outputs causing unnecessary rebuilds; missing FileWrites registration. Covers DependsOnTargets vs BeforeTargets vs AfterTargets, the Build→CoreBuild three-level pattern, and the $(XxxDependsOn) chain
How do I install it?
Run `npx skills add dotnet/skills --skill target-authoring --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From dotnet/skills, a repository with 4,927 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
