aboutsummaryrefslogtreecommitdiff
path: root/src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.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/RefreshGeneratedFile.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/RefreshGeneratedFile.cs')
-rw-r--r--src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.cs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.cs b/src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.cs
new file mode 100644
index 00000000..1e43cc1f
--- /dev/null
+++ b/src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.cs
@@ -0,0 +1,91 @@
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 that contains ComponentGroupRefs
14 /// to harvested output.
15 /// </summary>
16 public class RefreshGeneratedFile : RefreshTask
17 {
18 /// <summary>
19 /// Gets a complete list of external cabs referenced by the given installer database file.
20 /// </summary>
21 /// <returns>True upon completion of the task execution.</returns>
22 public override bool Execute()
23 {
24 var componentGroupRefs = new ArrayList();
25
26 for (var i = 0; i < this.ProjectReferencePaths.Length; i++)
27 {
28 var item = this.ProjectReferencePaths[i];
29
30 if (!String.IsNullOrEmpty(item.GetMetadata(DoNotHarvest)))
31 {
32 continue;
33 }
34
35 var projectPath = item.GetMetadata("MSBuildSourceProjectFile");
36 var projectName = Path.GetFileNameWithoutExtension(projectPath);
37 var referenceName = GetIdentifierFromName(GetMetadataOrDefault(item, "Name", projectName));
38
39 var pogs = item.GetMetadata("RefProjectOutputGroups").Split(';');
40 foreach (var pog in pogs)
41 {
42 if (!String.IsNullOrEmpty(pog))
43 {
44 componentGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog));
45 }
46 }
47 }
48
49 var doc = new XmlDocument();
50
51 var head = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
52 doc.AppendChild(head);
53
54 var rootElement = doc.CreateElement("Wix");
55 rootElement.SetAttribute("xmlns", "http://wixtoolset.org/schemas/v4/wxs");
56 doc.AppendChild(rootElement);
57
58 var fragment = doc.CreateElement("Fragment");
59 rootElement.AppendChild(fragment);
60
61 var componentGroup = doc.CreateElement("ComponentGroup");
62 componentGroup.SetAttribute("Id", "Product.Generated");
63 fragment.AppendChild(componentGroup);
64
65 foreach (string componentGroupRef in componentGroupRefs)
66 {
67 var componentGroupRefElement = doc.CreateElement("ComponentGroupRef");
68 componentGroupRefElement.SetAttribute("Id", componentGroupRef);
69 componentGroup.AppendChild(componentGroupRefElement);
70 }
71
72 foreach (var item in this.GeneratedFiles)
73 {
74 var fullPath = item.GetMetadata("FullPath");
75
76 componentGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath));
77 try
78 {
79 doc.Save(fullPath);
80 }
81 catch (Exception e)
82 {
83 // e.Message will be something like: "Access to the path 'fullPath' is denied."
84 this.Log.LogMessage(MessageImportance.High, "Unable to save generated file to '{0}'. {1}", fullPath, e.Message);
85 }
86 }
87
88 return true;
89 }
90 }
91}