Skip to content

docs: document Directory.Build.props/targets hierarchy in agent instruction files#4984

Merged
jamescrosswell merged 3 commits intomainfrom
copilot/add-guidance-directory-build-files
Mar 5, 2026
Merged

docs: document Directory.Build.props/targets hierarchy in agent instruction files#4984
jamescrosswell merged 3 commits intomainfrom
copilot/add-guidance-directory-build-files

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

#skip-changelog

AI coding tools frequently mishandle MSBuild's hierarchical Directory.Build.props/.targets resolution — the nearest file wins and parent files are not automatically inherited unless explicitly imported.

Changes

  • AGENTS.md (symlinked as CLAUDE.md and .github/copilot-instructions.md): expanded the Build System section to explain the "nearest wins" MSBuild lookup rule and lists all subdirectory-level overrides:
File(s) Purpose
src/Directory.Build.{props,targets} Source packaging, SourceLink, nullability, AOT settings
test/Directory.Build.{props,targets} xUnit, NSubstitute, Verify test settings
samples/Directory.Build.{props,targets} Sample app settings
benchmarks/Directory.Build.props Benchmark settings
integration-test/Directory.Build.{props,targets} Intentionally isolated — does not import root

All subdirectory files (except integration-test/) explicitly <Import> the root Directory.Build.props/.targets.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add guidance for Directory.Build.props and Directory.Build.targets to agents.md file</issue_title>
<issue_description>question: Directory.Build.props and Directory.Build.targets in sub-directories?

I noticed quite often that AI coding tools don't get MSBuild's hierarchical structure correctly:

  1. first Directory.Build.props/.targets found upwards from the project's location
  2. more parent Directory.Build.props/.targets files only if imported explicitly

So I'm wondering, if we should mention the other files, too ... something like:

- `samples/Directory.Build.props` / `samples/Directory.Build.targets` - shared MSBuild properties across all projects in the `samples` directory
- `src/Directory.Build.props` / `src/Directory.Build.targets` - shared MSBuild properties across all projects in the `src` directory
- `test/Directory.Build.props` / `test/Directory.Build.targets` - shared MSBuild properties across all projects in the `test` directory

Originally posted by @Flash0ver in #4974 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…nstruction files

Co-Authored-By: GitHub Copilot <copilot@github.com>

Co-authored-by: jamescrosswell <728212+jamescrosswell@users.noreply.github.com>
Copilot AI changed the title [WIP] Add guidance for Directory.Build.props and Directory.Build.targets docs: document Directory.Build.props/targets hierarchy in agent instruction files Mar 4, 2026
Clarify MSBuild hierarchical structure and overrides.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@jamescrosswell jamescrosswell marked this pull request as ready for review March 5, 2026 01:31

### MSBuild hierarchical structure

MSBuild searches upward from each project file and uses the **nearest** `Directory.Build.props`/`.targets` it finds. Parent files are not automatically included. props/targets files in this repo explicitly `<Import>` parent/root files when appropriate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: link to Microsoft docs

Shall we have a markdown link to the MSBuild docs?
https://learn.microsoft.com/visualstudio/msbuild/customize-by-directory?view=visualstudio#directorybuildprops-and-directorybuildtargets

Or would links in AGENTS.md just clutter the context?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The risk is that it follows the link, which will slow it down and add way more context than we really want... so no, I don't think we want to do that. If it keeps stuffing things up re props/targets files even with these instructions, I think we should look at improving these summary/concise instructions rather than linking to docs that are designed to be read by humans.

@jamescrosswell jamescrosswell merged commit cb5edd3 into main Mar 5, 2026
14 checks passed
@jamescrosswell jamescrosswell deleted the copilot/add-guidance-directory-build-files branch March 5, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add guidance for Directory.Build.props and Directory.Build.targets to agents.md file

3 participants