summaryrefslogtreecommitdiff
path: root/src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-07-26 17:20:39 -0700
committerRob Mensching <rob@firegiant.com>2022-08-01 20:25:19 -0700
commita627ca9b720047e633a8fe72003ab9bee31006c5 (patch)
tree2bc8a924bb4141ab718e74d08f6459a0ffe8d573 /src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs
parent521eb3c9cf38823a2c4019abb85dc0b3200b92cb (diff)
downloadwix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.gz
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.bz2
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.zip
Create WixToolset.Heat.nupkg to distribute heat.exe and Heat targets
Moves Heat functionality to the "tools" layer and packages it all up in WixToolset.Heat.nupkg for distribution in WiX v4. Completes 6838
Diffstat (limited to 'src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs')
-rw-r--r--src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs b/src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs
new file mode 100644
index 00000000..8f1ad167
--- /dev/null
+++ b/src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs
@@ -0,0 +1,104 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.HeatTasks
4{
5 using System;
6 using System.Collections;
7 using System.Globalization;
8 using System.IO;
9 using System.Xml;
10 using Microsoft.Build.Framework;
11
12 /// <summary>
13 /// This task refreshes the generated file for bundle projects.
14 /// </summary>
15 public class RefreshBundleGeneratedFile : RefreshTask
16 {
17 /// <summary>
18 /// Gets a complete list of external cabs referenced by the given installer database file.
19 /// </summary>
20 /// <returns>True upon completion of the task execution.</returns>
21 public override bool Execute()
22 {
23 var payloadGroupRefs = new ArrayList();
24 var packageGroupRefs = new ArrayList();
25 for (var i = 0; i < this.ProjectReferencePaths.Length; i++)
26 {
27 var item = this.ProjectReferencePaths[i];
28
29 if (!String.IsNullOrEmpty(item.GetMetadata(DoNotHarvest)))
30 {
31 continue;
32 }
33
34 var projectPath = item.GetMetadata("MSBuildSourceProjectFile");
35 var projectName = Path.GetFileNameWithoutExtension(projectPath);
36 var referenceName = GetIdentifierFromName(GetMetadataOrDefault(item, "Name", projectName));
37
38 var pogs = item.GetMetadata("RefProjectOutputGroups").Split(';');
39 foreach (var pog in pogs)
40 {
41 if (!String.IsNullOrEmpty(pog))
42 {
43 // TODO: Add payload group references and package group references once heat is generating them
44 ////payloadGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog));
45 packageGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog));
46 }
47 }
48 }
49
50 var doc = new XmlDocument();
51
52 var head = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
53 doc.AppendChild(head);
54
55 var rootElement = doc.CreateElement("Wix");
56 rootElement.SetAttribute("xmlns", "http://wixtoolset.org/schemas/v4/wxs");
57 doc.AppendChild(rootElement);
58
59 var fragment = doc.CreateElement("Fragment");
60 rootElement.AppendChild(fragment);
61
62 var payloadGroup = doc.CreateElement("PayloadGroup");
63 payloadGroup.SetAttribute("Id", "Bundle.Generated.Payloads");
64 fragment.AppendChild(payloadGroup);
65
66 var packageGroup = doc.CreateElement("PackageGroup");
67 packageGroup.SetAttribute("Id", "Bundle.Generated.Packages");
68 fragment.AppendChild(packageGroup);
69
70 foreach (string payloadGroupRef in payloadGroupRefs)
71 {
72 var payloadGroupRefElement = doc.CreateElement("PayloadGroupRef");
73 payloadGroupRefElement.SetAttribute("Id", payloadGroupRef);
74 payloadGroup.AppendChild(payloadGroupRefElement);
75 }
76
77 foreach (string packageGroupRef in packageGroupRefs)
78 {
79 var packageGroupRefElement = doc.CreateElement("PackageGroupRef");
80 packageGroupRefElement.SetAttribute("Id", packageGroupRef);
81 packageGroup.AppendChild(packageGroupRefElement);
82 }
83
84 foreach (var item in this.GeneratedFiles)
85 {
86 var fullPath = item.GetMetadata("FullPath");
87
88 payloadGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath) + ".Payloads");
89 packageGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath) + ".Packages");
90 try
91 {
92 doc.Save(fullPath);
93 }
94 catch (Exception e)
95 {
96 // e.Message will be something like: "Access to the path 'fullPath' is denied."
97 this.Log.LogMessage(MessageImportance.High, "Unable to save generated file to '{0}'. {1}", fullPath, e.Message);
98 }
99 }
100
101 return true;
102 }
103 }
104}