Skip to content

Instantly share code, notes, and snippets.

@shadow-cs
Last active November 18, 2021 09:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shadow-cs/cb5499b010bdacd1f778be29daf7f04c to your computer and use it in GitHub Desktop.
Save shadow-cs/cb5499b010bdacd1f778be29daf7f04c to your computer and use it in GitHub Desktop.
MSBuild: Selecting first and last items in an ItemGroup
<Project DefaultTargets="Default">
<ItemGroup>
<Items Include="One;Two;Three;Four;Five" />
</ItemGroup>
<Target Name="Default">
<ItemGroup>
<Reversed Include="@(Items->Reverse())" />
</ItemGroup>
<PropertyGroup>
<First>%(Reversed.Identity)</First>
<Last>%(Items.Identity)</Last>
</PropertyGroup>
<Warning Text="First: $(First)" />
<Warning Text="Last: $(Last)" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment