Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

Context

Per feedback from maintainers, documentation for the MSB4191 error (ItemGroup conditions using metadata batching syntax failing at project level) should be placed in the mainline public docs (msbuild-api-docs repository) rather than in this repository.

Changes Made

  • Reverted /documentation/wiki/Common-MSBuild-Gotchas.md - removed the documentation file that was originally created
  • Reverted /documentation/README.md - removed the link to the documentation file
  • Added MSB4191-Documentation-Transfer.md - complete documentation content ready for transfer to msbuild-api-docs repository

The transfer document includes:

Testing

  • ✅ Verified all changes were completely reverted
  • ✅ Repository is in clean state with no uncommitted changes
  • ✅ Documentation files successfully removed
  • ✅ All code examples in transfer document previously tested and verified working
  • ✅ Transfer document is well-structured and ready for copy-paste into msbuild-api-docs

Notes

The documentation content in MSB4191-Documentation-Transfer.md is ready to be transferred to the dotnet/msbuild-api-docs repository as mainline public documentation. This PR keeps this repository focused on implementation while providing maintainers with complete, ready-to-use documentation content.

Original prompt

This section details on the original issue you should resolve

<issue_title>ItemGroup item condition with metadata doesn't work in Project</issue_title>
<issue_description>ItemGroup with an item which has a condition with item metadata doesn't work in Project, but it works in a Target.

Steps to reproduce

Example ItemGroup

<ItemGroup>
    <ContentX Include="@(Content)" Condition="'%(Content.X)' == 'abc'" />
</ItemGroup>

This works in a Target, but not in Project.

Command line

msbuild

or

dotnet build

Expected behavior

It uses the metadata to evaluate the condition.

Actual behavior

It throws an exception:

error MSB4191: The reference to custom metadata "X" at position 1 is not allowed in this condition "'%(Content.X)' == 'abc'".

Environment data

msbuild /version output:
15.7.179.6572

OS info:
Windows 10

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):

  • Visual Studio: 15.7.4.
  • .NET CLI: 2.1.300.</issue_description>

<agent_instructions>create documentation for this limitation in the repo</agent_instructions>

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

@danmoseley It's always been this way -- outside of Targets, each element is evaluated as a single entity, whereas syntax like ` Condition="'%(Content.X)' == 'abc'"` implies "batching" -- evaluating for each distinct bucket, which only happens inside of Targets. Later, filtering like `->WithMetadataValue('X','abc')` became possible.

I don't know of a fundamental reason why batching can't happen outside of targets, at least on Conditions, if someone was willing to do all the work and prove that performance wasn't negatively impacted.</comment_new>


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

@dotnet-policy-service
Copy link
Contributor

Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Copilot AI changed the title [WIP] Fix item condition with metadata in Project Document item metadata condition limitation (MSB4191) Jan 19, 2026
Copilot AI requested a review from YuliiaKovalova January 19, 2026 10:35
@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review January 19, 2026 10:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR documents a common MSBuild limitation (MSB4191 error) where item metadata conditions fail at the project level but work inside targets. This addresses a frequently encountered issue where developers attempt to use batching syntax outside of target execution.

Changes:

  • Created comprehensive documentation explaining the MSB4191 error, its cause, and three practical workarounds
  • Added link to the new documentation from the main README's "Problems?" section

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
documentation/wiki/Common-MSBuild-Gotchas.md New documentation file explaining the item metadata condition limitation with examples and workarounds
documentation/README.md Added link to the new Common-MSBuild-Gotchas.md file in the Problems section


For more context on why this limitation exists, see:
- [MSBuild Architecture Overview](../Contributions/MSBuild-overview.md) - explains the difference between evaluation and execution phases
- Issue [#3520](https://github.com/dotnet/msbuild/issues/3520) - original issue tracking this limitation
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The issue number referenced here (#3520) does not match the issue number mentioned in the PR description (#3479). The link should point to the correct issue that this documentation is addressing.

Suggested change
- Issue [#3520](https://github.com/dotnet/msbuild/issues/3520) - original issue tracking this limitation
- Issue [#3479](https://github.com/dotnet/msbuild/issues/3479) - original issue tracking this limitation

Copilot uses AI. Check for mistakes.
@rainersigwald
Copy link
Member

I think this should go in the mainline public docs, not in this repo.

@YuliiaKovalova
Copy link
Member

@copilot could you please move these changes to https://github.com/dotnet/msbuild-api-docs/pulls repo?

Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot could you please move these changes to https://github.com/dotnet/msbuild-api-docs/pulls repo?

I've reverted the documentation changes from this repository in commit ce66be7.

However, I can only work within the dotnet/msbuild repository. The documentation content would need to be created in the msbuild-api-docs repository by someone with access to that repository.

The reverted documentation included:

  • Explanation of MSB4191 error and batching limitation
  • Examples of failing vs. working code
  • Three workarounds (moving to targets, using WithMetadataValue(), other item functions)
  • Links to related documentation

Would you like me to provide the documentation content in a format that can be easily transferred to the msbuild-api-docs repository?

Copilot AI changed the title Document item metadata condition limitation (MSB4191) Revert documentation changes - to be moved to msbuild-api-docs repo Jan 26, 2026
@YuliiaKovalova
Copy link
Member

@copilot
Would you like me to provide the documentation content in a format that can be easily transferred to the msbuild-api-docs repository? - yes, please do that

Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot
Would you like me to provide the documentation content in a format that can be easily transferred to the msbuild-api-docs repository? - yes, please do that

I've added the complete documentation content in MSB4191-Documentation-Transfer.md (commit 71d5e19).

The file includes:

The content is ready to copy-paste into msbuild-api-docs or adapt to fit its structure.

Copilot AI changed the title Revert documentation changes - to be moved to msbuild-api-docs repo Provide MSB4191 documentation content for transfer to msbuild-api-docs Jan 26, 2026
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.

ItemGroup item condition with metadata doesn't work in Project

3 participants