Created
May 10, 2017 13:52
-
-
Save Serivy/74fff320c93176e6ca7f76e1cc139367 to your computer and use it in GitHub Desktop.
Gets the first item from an item group.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<UsingTask TaskName="GetFirstItem" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> | |
<ParameterGroup> | |
<Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | |
<FirstItem ParameterType="System.String" Output="true" Required="false" /> | |
</ParameterGroup> | |
<Task> | |
<Using Namespace="System.Linq"/> | |
<Code Type="Fragment" Language="cs">FirstItem = Items.First().ItemSpec;</Code> | |
</Task> | |
</UsingTask> | |
<Target Name="UseCase"> | |
<ItemGroup> | |
<ItemList Include="first;second;third"/> | |
</ItemGroup> | |
<GetFirstItem Items="@(ItemList)"> | |
<Output TaskParameter="FirstItem" PropertyName="FirstItemProperty"/> | |
</GetFirstItem> | |
<Message Text="First item is: $(FirstItemProperty)" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment