property-patterns

Diagnose and fix MSBuild property definition issues in .props and .csproj files.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? MSBuild properties are easy to get wrong: unconditional assignments block overrides, DefineConstants get overwritten instead of appended, unquoted conditions fail on empty values, and hardcoded paths break cross-platform builds. This Skill provides canonical patterns from the MSBuild repository to diagnose and fix these property definition issues. ## Core Features & Use Cases - Conditional Defaults: Set overridable defaults with Condition="'$(Prop)' == ''" so callers can override values from the command line or project files. - Composition and Concatenation: Append to list properties like DefineConstants and NoWarn using semicolon concatenation instead of overwriting prior values. - Path Normalization and TFM Detection: Normalize paths cross-platform, handle trailing slashes, and detect target frameworks with GetTargetFrameworkIdentifier and IsTargetFrameworkCompatible. - Use Case: A team's Directory.Build.props sets <DefineConstants>MY_FLAG</DefineConstants> unconditionally, silently dropping constants defined elsewhere. Use this Skill to rewrite it as an append pattern and add proper quoting to all conditions. ## Quick Start Review my Directory.Build.props and csproj files for property definition anti-patterns and fix any overwritten DefineConstants or missing conditional defaults.

Frequently Asked Questions about property-patterns

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

FAQPage Schema
How do I set a default MSBuild property that can be overridden?

Use a conditional default: `<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>`. The condition only assigns the value when the property is empty, so command-line or project-level values take precedence. Always quote both sides of the comparison.

How to append to DefineConstants in MSBuild without overwriting?

Append using semicolon concatenation: `<DefineConstants>$(DefineConstants);MY_FEATURE</DefineConstants>`. Writing `<DefineConstants>MY_FEATURE</DefineConstants>` alone drops all previously defined constants, which is a common source of broken builds.

Why does my MSBuild condition fail when the property is empty?

Unquoted conditions like `$(X)==true` produce invalid syntax when $(X) expands to nothing. Always quote both sides: `'$(X)' == 'true'`, so an empty property evaluates as `'' == 'true'` instead of causing a parse error.

Can I use TargetFramework conditions in .props files?

Not reliably for single-targeting projects. $(TargetFramework) is empty in .props files until the project body is evaluated. Place TargetFramework-conditioned property groups in .targets files or the project file itself, where the value is always available.

How do I make MSBuild paths work cross-platform?

Use `$([MSBuild]::NormalizePath(...))` to combine and normalize paths, and `$(MSBuildThisFileDirectory)` instead of hardcoded absolute paths. Check trailing slashes with HasTrailingSlash and verify rooted paths with System.IO.Path.IsPathRooted.

When should I not use this property patterns skill?

Use other skills for props vs targets placement decisions, item operations, target authoring, or general MSBuild anti-patterns. This skill covers only property definition and manipulation patterns, not non-MSBuild build systems.