Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WithoutMetadataValue #8867

Merged
merged 3 commits into from
Jun 27, 2023
Merged

Add WithoutMetadataValue #8867

merged 3 commits into from
Jun 27, 2023

Conversation

JaynieBai
Copy link
Member

@JaynieBai JaynieBai commented Jun 12, 2023

Fixes #8205

Context

The following set of item functions allow to condition on or filter items based on metadata:

AnyHaveMetdataValue
HasMetadata
WithMetadataValue
These functions make it super simple to include items or condition based on metadata during evaluation time, without the need of batching (inside a target).

Over the last years I often wished that there would also be a WithoutMetadataValue item function so that the following pattern wouldn't require an extra target:

<Target Name="GetCompileFilteredItems">
  <ItemGroup>
    <CompileFiltered Include="@(Compile->WithMetadataValue('ExcludeFromX', ''))" />
    <CompileFiltered Include="@(Compile->WithMetadataValue('ExcludeFromX', 'false'))" />
  </ItemGroup>
</Target>

<Target Name="X"
             Inputs="@(CompileFiltered)"
             Outputs="..."
             DependsOnTargets="GetCompileFilteredItems">
  ...
</Target>

Instead, with a WithoutMetadtaValue item function, the filtering can happen just in-time without a separate target.

<Target Name="X"
             Inputs="@(Compile->WithoutMetadataValue('ExcludeFromX', 'true'))"
             Outputs="...">
  ...
</Target>

Changes Made

Add one new function WithoutMetadataValue

Testing

Add one test WithoutMetadataValue()

Notes

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

I'm wondering if you could consolidate parts of this with WithMetadataValue, but it looks fine to me overall. Thanks!

src/Build/Evaluation/Expander.cs Show resolved Hide resolved
Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

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

Looks good

src/Build/Evaluation/Expander.cs Outdated Show resolved Hide resolved
@JaynieBai
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rainersigwald rainersigwald added this to the VS 17.8 milestone Jun 22, 2023
@JaynieBai JaynieBai merged commit a0468d8 into main Jun 27, 2023
@JaynieBai JaynieBai deleted the Jennybai/withoutmetadatavalue branch June 27, 2023 01:52
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.

Consider adding a WithoutMetadataValue msbuild item function
4 participants