Skip to content

Instantly share code, notes, and snippets.

@jrusbatch
Created April 28, 2013 23:05
Show Gist options
  • Save jrusbatch/5478788 to your computer and use it in GitHub Desktop.
Save jrusbatch/5478788 to your computer and use it in GitHub Desktop.
<UsingTask TaskName="CombinePackageConfigs" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<PackageConfigFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<OutputPath ParameterType="System.String" Required="true" />
<CreatedFile ParameterType="Microsoft.Build.Framework.ITaskItem" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Using Namespace="System.Xml" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var packages =
PackageConfigFiles.AsParallel()
.Select(x => XDocument.Load(x.GetMetadata("FullPath")))
.SelectMany(x => x.Root.Elements("package"))
.Select(x => new { Id = (string)x.Attribute("id"), Version = (string)x.Attribute("version") })
.Distinct();
var document =
new XDocument(
new XElement("packages",
packages.Select(x => new XElement("package", new XAttribute("id", x.Id), new XAttribute("version", x.Version)))));
document.Save(OutputPath);
]]>
</Code>
</Task>
</UsingTask>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment