Created
May 13, 2013 23:22
-
-
Save vadimi/5572381 to your computer and use it in GitHub Desktop.
Simple MSBuild task to find items in ItemGroup
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
<UsingTask TaskName="FindInEnumeration" TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |
<ParameterGroup> | |
<SourceFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | |
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" /> | |
</ParameterGroup> | |
<Task> | |
<Reference Include="System" /> | |
<Reference Include="System.Core" /> | |
<Reference Include="System.Xml" /> | |
<Reference Include="System.Xml.Linq" /> | |
<Reference Include="Microsoft.CSharp" /> | |
<Using Namespace="System" /> | |
<Using Namespace="System.Reflection" /> | |
<Using Namespace="System.IO" /> | |
<Using Namespace="System.Linq" /> | |
<Using Namespace="System.Xml.Linq" /> | |
<Using Namespace="System.Net" /> | |
<Using Namespace="Microsoft.Build.Framework" /> | |
<Using Namespace="Microsoft.Build.Utilities" /> | |
<Code Type="Fragment" Language="cs"> | |
<![CDATA[ | |
try | |
{ | |
var filesToFind = Files.Select(item => item.GetMetadata("FullPath")).ToArray(); | |
Result = SourceFiles | |
.Where(file => filesToFind.Contains(file.ItemSpec)) | |
.ToArray(); | |
return true; | |
} | |
catch (Exception ex) | |
{ | |
Log.LogErrorFromException(ex); | |
return false; | |
} | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment