Skip to content

Instantly share code, notes, and snippets.

@mika76
Last active June 24, 2016 06:01
Show Gist options
  • Save mika76/929c3e8d8d624ada62577afac419c6b7 to your computer and use it in GitHub Desktop.
Save mika76/929c3e8d8d624ada62577afac419c6b7 to your computer and use it in GitHub Desktop.
Replacement for HeatDirectory since heat.exe throws a BadImageFormatException when running msbuild in 64 bit
<UsingTask
TaskName="CustomHeatDirectory"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Directory Required="true" />
<DirectoryRefId Required="true" />
<ComponentGroupName Required="true" />
<OutputFile Required="true" />
<GenerateGuidsNow Required="true" />
<PreprocessorVariable Required="true" />
<SuppressFragments Required="true" />
<SuppressRootDirectory Required="true" />
<ToolPath Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.Linq"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml"/>
<Using Namespace="System.Xml.Linq"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Harvesting folder " + Directory, MessageImportance.Normal);
var files = (from f in System.IO.Directory.EnumerateFiles(this.Directory, "*.*", SearchOption.AllDirectories)
where f.EndsWith(".rpt", StringComparison.InvariantCultureIgnoreCase) || f.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)
select new
{
FilePath = f,
Source = "$" + String.Format("({0})\\{1}", this.PreprocessorVariable, Path.GetFileName(f)),
ComponentId = "cmp" + Guid.NewGuid().ToString("N").ToUpper(),
Guid = Guid.NewGuid().ToString("B"),
FileId = "fil" + Guid.NewGuid().ToString("N").ToUpper()
})
.ToList();
XNamespace wi = "http://schemas.microsoft.com/wix/2006/wi";
var xml = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(wi + "Wix",
new XElement(wi + "Fragment",
new XElement(wi + "DirectoryRef", new XAttribute("Id", DirectoryRefId),
files.Select(f =>
new XElement(wi + "Component", new XAttribute("Id", f.ComponentId), new XAttribute("Guid", f.Guid),
new XElement(wi + "File", new XAttribute("Id", f.FileId), new XAttribute("KeyPath", "yes"), new XAttribute("Source", f.Source)
)
)
)
)
),
new XElement(wi + "Fragment",
new XElement(wi + "ComponentGroup", new XAttribute("Id", ComponentGroupName),
files.Select(f =>
new XElement(wi + "ComponentRef", new XAttribute("Id", f.ComponentId))
)
)
)
)
);
xml.Save(OutputFile);
Log.LogMessage("Saved "+ files.Count() + " files to " + OutputFile, MessageImportance.Low);
]]>
</Code>
</Task>
</UsingTask>
<!--
<CustomHeatDirectory
Directory=".\..\HeatReports"
DirectoryRefId="INSTALL_REPORTS"
ComponentGroupName ="rpts"
OutputFile=".\..\Package\Reports.wxs"
GenerateGuidsNow="true"
PreprocessorVariable="var.ReportPath"
SuppressFragments ="true"
SuppressRootDirectory ="true"
ToolPath="$(WixToolPath)"
/>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment