npx skills add ...
npx skills add dotnet/skills --skill property-patterns
MSBuild property definition patterns: conditional defaults, composition/concatenation, path normalization, trailing-slash handling, TFM detection helpers, and evaluation order. USE FOR: diagnosing and fixing property definition issues and shared-property anti-patterns in .props/.csproj; DefineConstants or NoWarn overwritten instead of appended; unconditional assignments that block project-level overrides; unquoted conditions that fail on empty properties; hardcoded paths that break cross-platform builds; setting overridable defaults; property evaluation order and last-write-wins semantics. DO NOT USE FOR: props vs targets placement (use directory-build-organization), item operations (use item-management), target structure (use target-authoring), general anti-patterns (use msbuild-antipatterns), non-MSBuild build systems.
npx skills add dotnet/skills --skill property-patterns
Canonical property definition and manipulation patterns from the MSBuild repository.
Set a property only if not already set, allowing callers to override:
'$(Prop)' == ''.props: creates overridable defaults. In .targets: creates fallbacks.Group related properties under a shared condition:
Use the outer Condition on PropertyGroup to avoid repeating the same condition on every property.
Warning:
$(TargetFramework)is empty in.propsfiles for single-targeting projects until the project body is evaluated. PlaceTargetFramework-conditioned property groups in.targetsfiles (or the project file itself), where the value is always available.
Properties that hold lists use semicolons. Always include the existing value when appending:
| Function | Purpose |
|---|---|
$([MSBuild]::NormalizePath(...)) | Combine and normalize (cross-platform) |
$([System.IO.Path]::Combine(...)) | Combine path segments |
$([System.IO.Path]::IsPathRooted(...)) | Check if absolute |
HasTrailingSlash(...) | Check for trailing slash |
$([MSBuild]::GetDirectoryNameOfFileAbove(...)) | Walk up directory tree |
$(MSBuildThisFileDirectory) | Directory of current file |
Mark that a file has been imported to prevent double-imports:
Set via primary source first, then fall back:
MSBuild evaluates properties top-to-bottom. The last assignment wins:
Properties in .targets (imported late) override properties in .props (imported early) and the project file.
$(X)==true) fail when the property is empty. Always quote both sides.<DefineConstants>MY_CONST</DefineConstants>) drops all prior constants. Always append with $(DefineConstants);.$(MSBuildThisFileDirectory) or $([MSBuild]::NormalizePath(...)).Condition on defaults makes properties non-overridable. Add Condition="'$(Prop)' == ''" for values meant to be defaults.