directory-build-organization

Featured

Guide for organizing MSBuild infrastructure with Directory.Build.props, Directory.Build.targets, Directory.Packages.props, and Directory.Build.rsp. Only activate in MSBuild/.NET build context. USE FOR: structuring multi-project repos, centralizing build settings, implementing NuGet Central Package Management (CPM) with ManagePackageVersionsCentrally, consolidating duplicated properties across .csproj files, setting up multi-level Directory.Build hierarchy with GetPathOfFileAbove, understanding evaluation order (Directory.Build.props → SDK .props → .csproj → SDK .targets → Directory.Build.targets). Critical pitfall: $(TargetFramework) conditions in .props silently fail for single-targeting projects — must use .targets. DO NOT USE FOR: non-MSBuild build systems, migrating legacy projects to SDK-style (use msbuild-modernization), single-project solutions with no shared settings. INVOKES: no tools — pure knowledge skill.

Web & Frontend 6,272 stars 499 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Organizing Build Infrastructure with Directory.Build Files ## Directory.Build.props vs Directory.Build.targets Understanding which file to use is critical. They differ in **when** they are imported during evaluation: **Evaluation order:** ``` Directory.Build.props → SDK .props → YourProject.csproj → SDK .targets → Directory.Build.targets ``` | Use `.props` for | Use `.targets` for | |---|---| | Setting property defaults | Custom build targets | | Common item definitions | Late-bound property overrides | | Properties projects can override | Post-build steps | | Assembly/package metadata | Conditional logic on final values | | Analyzer PackageReferences | Targets that depend on SDK-defined properties | **Rule of thumb:** Properties and items go in `.props`. Custom targets and late-bound logic go in `.targets`. Because `.props` is imported before the project file, the project can override any value set there. Because `.targets` is imported after everything, it gets the final say—but projects cannot override `.targets` values. ### ⚠️ Critical: TargetFramework Availability in .props vs .targets **Property conditions on `$(TargetFramework)` in `.props` files silently fail for single-targeting projects** — the property is empty during `.props` evaluation. Move TFM-conditional properties to `.targets` instead. ItemGroup and Target conditions are not affected. See [targetframework-props-pitfall.md](references/targetframework-props-pitfall.md) for the full explanation. ## ...

Details

Author
dotnet
Repository
dotnet/skills
Created
9 months ago
Last Updated
today
Language
C#
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Listed

build-dotnet

How a .NET repository is built, versioned and restored — the house conventions on top of MSBuild and NuGet. Use when creating a repo or a project, editing Directory.Build.props, Directory.Packages.props or a .csproj, adding or bumping a package, versioning a release, packing a library, configuring the private feed, or when a restore or a build fails on the audit gate. It encodes: the three-tier Directory.Build.props, one VersionPrefix per repo (and the separately released piece that keeps its own), Central Package Management, a three-day minimum age for third-party versions, the NuGet vulnerability audit as a build gate, global.json, packing metadata for libraries, and a nuget.config that holds no credentials.

2 Updated 2 days ago
JorgeCostaMacia
Web & Frontend Featured

msbuild-antipatterns

Catalog of MSBuild anti-patterns with detection rules and fix recipes. Only activate in MSBuild/.NET build context. USE FOR: reviewing, auditing, or cleaning up .csproj, .vbproj, .fsproj, .props, .targets, or .proj files. Each anti-pattern has a symptom, explanation, and concrete BAD→GOOD transformation. Covers Exec-instead-of-built-in-task, unquoted conditions, hardcoded paths, restating SDK defaults, scattered package versions, and more. DO NOT USE FOR: non-MSBuild build systems (npm, Maven, CMake, etc.), project migration to SDK-style (use msbuild-modernization).

6,272 Updated today
dotnet
Data & Documents Featured

msbuild-modernization

Guide for modernizing and migrating MSBuild project files to SDK-style format. Only activate in MSBuild/.NET build context. USE FOR: converting legacy .csproj/.vbproj with verbose XML to SDK-style, migrating packages.config to PackageReference, removing Properties/AssemblyInfo.cs in favor of auto-generation, eliminating explicit <Compile Include> lists via implicit globbing, consolidating shared settings into Directory.Build.props. Indicators of legacy projects: ToolsVersion attribute, <Import Project="$(MSBuildToolsPath)">, .csproj files > 50 lines for simple projects. DO NOT USE FOR: projects already in SDK-style format, non-.NET build systems (npm, Maven, CMake), .NET Framework projects that cannot move to SDK-style. INVOKES: dotnet try-convert, upgrade-assistant tools.

6,272 Updated today
dotnet