target-authoring

Diagnoses and fixes custom MSBuild target authoring anti-patterns using canonical SDK patterns.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Custom MSBuild targets frequently break builds in subtle ways: Directory.Build.targets silently redefining SDK targets, CompileDependsOn chains overwritten instead of extended, query targets returning stale results due to Outputs vs Returns misuse, and missing Inputs/Outputs causing unnecessary rebuilds. This Skill provides canonical patterns from Microsoft.Common.CurrentVersion.targets to author and repair custom targets correctly. ## Core Features & Use Cases - Three-Level Target Chain: Implements the Build → CoreBuild pattern with DependsOnTargets property delegation, empty Before/After extensibility hooks, and OnError cleanup handlers. - Chain Extension Rules: Enforces appending to $(XxxDependsOn) properties instead of overwriting them, and guides correct choice between DependsOnTargets, BeforeTargets, and AfterTargets. - Returns vs Outputs Guidance: Distinguishes inter-project communication (Returns) from incremental build detection (Outputs) so query targets like GetTargetPath never return stale data. - Use Case: A team's Directory.Build.targets redefines CompileDependsOn without including the original value, silently dropping SDK code generation targets. This Skill identifies the overwrite anti-pattern and rewrites it as an append, restoring the full build chain. ## Quick Start Ask the assistant to review your custom .targets file for MSBuild authoring anti-patterns and rewrite it following the canonical target chain patterns.

Frequently Asked Questions about target-authoring

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

FAQPage Schema
How do I add a custom target to the MSBuild Compile chain?

Append your target to the existing CompileDependsOn property using $(CompileDependsOn);MyTarget rather than redefining it. Overwriting the property silently drops SDK targets like code generation, breaking the build chain.

What is the difference between DependsOnTargets, BeforeTargets, and AfterTargets in MSBuild?

DependsOnTargets declares prerequisites a target explicitly requires. BeforeTargets and AfterTargets inject your target into a pipeline you do not own, such as hooking BeforeTargets="CoreCompile" without modifying SDK files.

Why does my MSBuild query target return stale results?

Query targets like GetTargetPath that declare Outputs get skipped when MSBuild considers them up to date, returning stale data. Use Returns instead of Outputs for lightweight query targets with no side effects.

Should custom MSBuild targets go in .props or .targets files?

Custom targets belong in .targets files. Targets defined in .props are evaluated before SDK targets exist, so BeforeTargets hooks on SDK targets have nothing to attach to and silently fail.

How do I make a custom MSBuild target incremental?

Declare Inputs and Outputs on the core implementation target so MSBuild performs timestamp checks and skips up-to-date work. Also register generated files in the FileWrites item so Clean can remove them.

When should I not use this target authoring guidance?

This guidance covers authoring custom targets only. For incremental build tuning, build parallelization, or general MSBuild anti-patterns outside target authoring, use the dedicated incremental-build, build-parallelism, or msbuild-antipatterns skills instead.