Created
March 20, 2013 23:54
-
-
Save abombss/5209588 to your computer and use it in GitHub Desktop.
Dump ItemGroups and metadata from msbuild
This file contains hidden or 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 ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<UsingTask | |
TaskName="LogItems" | |
TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" > | |
<ParameterGroup> | |
<Items Required="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" /> | |
<Metadata ParameterType="Microsoft.Build.Framework.ITaskItem[]" /> | |
<Importance /> | |
</ParameterGroup> | |
<Task> | |
<Using Namespace="System" /> | |
<Using Namespace="System.Reflection" /> | |
<Using Namespace="System.Collections.Generic" /> | |
<Using Namespace="System.Linq" /> | |
<Using Namespace="Microsoft.Build.Framework" /> | |
<Code Type="Fragment" Language="cs"> | |
<![CDATA[ | |
MessageImportance level = (MessageImportance)Enum.Parse(typeof(MessageImportance), Importance ?? "Normal", false); | |
bool dumpAllMetadata = true; | |
bool dumpNoMetadata = false; | |
if (Metadata != null && Metadata.Count() == 1) | |
{ | |
if ("All".Equals(Metadata[0].ItemSpec, StringComparison.OrdinalIgnoreCase)) { | |
dumpAllMetadata = true; | |
dumpNoMetadata = false; | |
} else if ("None".Equals(Metadata[0].ItemSpec, StringComparison.OrdinalIgnoreCase)) { | |
dumpAllMetadata = false; | |
dumpNoMetadata = true; | |
} else { | |
dumpAllMetadata = false; | |
dumpNoMetadata = false; | |
} | |
} | |
foreach(var item in Items) | |
{ | |
Log.LogMessage(level, "Item: {0}", item.ItemSpec); | |
if (dumpNoMetadata) { continue; } | |
foreach(string mdName in item.MetadataNames) | |
{ | |
if (dumpAllMetadata || Metadata.Any(x => x.ItemSpec.Equals(mdName, StringComparison.OrdinalIgnoreCase))) { | |
Log.LogMessage(level, "\t{0} = {1}", mdName, item.GetMetadata(mdName)); | |
} | |
} | |
} | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment