diff options
author | Rob Mensching <rob@firegiant.com> | 2022-07-26 17:20:39 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-08-01 20:25:19 -0700 |
commit | a627ca9b720047e633a8fe72003ab9bee31006c5 (patch) | |
tree | 2bc8a924bb4141ab718e74d08f6459a0ffe8d573 /src/tools/WixToolset.HeatTasks | |
parent | 521eb3c9cf38823a2c4019abb85dc0b3200b92cb (diff) | |
download | wix-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')
-rw-r--r-- | src/tools/WixToolset.HeatTasks/HeatDirectory.cs | 47 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/HeatFile.cs | 44 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/HeatProject.cs | 72 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/HeatTask.cs | 176 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/RefreshBundleGeneratedFile.cs | 104 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/RefreshGeneratedFile.cs | 91 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/RefreshTask.cs | 59 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs | 56 | ||||
-rw-r--r-- | src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj | 17 |
9 files changed, 666 insertions, 0 deletions
diff --git a/src/tools/WixToolset.HeatTasks/HeatDirectory.cs b/src/tools/WixToolset.HeatTasks/HeatDirectory.cs new file mode 100644 index 00000000..8a169055 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/HeatDirectory.cs | |||
@@ -0,0 +1,47 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using Microsoft.Build.Framework; | ||
6 | |||
7 | public sealed class HeatDirectory : HeatTask | ||
8 | { | ||
9 | public string ComponentGroupName { get; set; } | ||
10 | |||
11 | [Required] | ||
12 | public string Directory { get; set; } | ||
13 | |||
14 | public string DirectoryRefId { get; set; } | ||
15 | |||
16 | public bool KeepEmptyDirectories { get; set; } | ||
17 | |||
18 | public string PreprocessorVariable { get; set; } | ||
19 | |||
20 | public bool SuppressCom { get; set; } | ||
21 | |||
22 | public bool SuppressRootDirectory { get; set; } | ||
23 | |||
24 | public bool SuppressRegistry { get; set; } | ||
25 | |||
26 | public string Template { get; set; } | ||
27 | |||
28 | protected override string OperationName => "dir"; | ||
29 | |||
30 | protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
31 | { | ||
32 | commandLineBuilder.AppendSwitch(this.OperationName); | ||
33 | commandLineBuilder.AppendFileNameIfNotNull(this.Directory); | ||
34 | |||
35 | commandLineBuilder.AppendSwitchIfNotNull("-cg ", this.ComponentGroupName); | ||
36 | commandLineBuilder.AppendSwitchIfNotNull("-dr ", this.DirectoryRefId); | ||
37 | commandLineBuilder.AppendIfTrue("-ke", this.KeepEmptyDirectories); | ||
38 | commandLineBuilder.AppendIfTrue("-scom", this.SuppressCom); | ||
39 | commandLineBuilder.AppendIfTrue("-sreg", this.SuppressRegistry); | ||
40 | commandLineBuilder.AppendIfTrue("-srd", this.SuppressRootDirectory); | ||
41 | commandLineBuilder.AppendSwitchIfNotNull("-template ", this.Template); | ||
42 | commandLineBuilder.AppendSwitchIfNotNull("-var ", this.PreprocessorVariable); | ||
43 | |||
44 | base.BuildCommandLine(commandLineBuilder); | ||
45 | } | ||
46 | } | ||
47 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/HeatFile.cs b/src/tools/WixToolset.HeatTasks/HeatFile.cs new file mode 100644 index 00000000..83cbc4d1 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/HeatFile.cs | |||
@@ -0,0 +1,44 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using Microsoft.Build.Framework; | ||
6 | |||
7 | public sealed class HeatFile : HeatTask | ||
8 | { | ||
9 | public string ComponentGroupName { get; set; } | ||
10 | |||
11 | public string DirectoryRefId { get; set; } | ||
12 | |||
13 | [Required] | ||
14 | public string File { get; set; } | ||
15 | |||
16 | public string PreprocessorVariable { get; set; } | ||
17 | |||
18 | public bool SuppressCom { get; set; } | ||
19 | |||
20 | public bool SuppressRegistry { get; set; } | ||
21 | |||
22 | public bool SuppressRootDirectory { get; set; } | ||
23 | |||
24 | public string Template { get; set; } | ||
25 | |||
26 | protected override string OperationName => "file"; | ||
27 | |||
28 | protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
29 | { | ||
30 | commandLineBuilder.AppendSwitch(this.OperationName); | ||
31 | commandLineBuilder.AppendFileNameIfNotNull(this.File); | ||
32 | |||
33 | commandLineBuilder.AppendSwitchIfNotNull("-cg ", this.ComponentGroupName); | ||
34 | commandLineBuilder.AppendSwitchIfNotNull("-dr ", this.DirectoryRefId); | ||
35 | commandLineBuilder.AppendIfTrue("-scom", this.SuppressCom); | ||
36 | commandLineBuilder.AppendIfTrue("-srd", this.SuppressRootDirectory); | ||
37 | commandLineBuilder.AppendIfTrue("-sreg", this.SuppressRegistry); | ||
38 | commandLineBuilder.AppendSwitchIfNotNull("-template ", this.Template); | ||
39 | commandLineBuilder.AppendSwitchIfNotNull("-var ", this.PreprocessorVariable); | ||
40 | |||
41 | base.BuildCommandLine(commandLineBuilder); | ||
42 | } | ||
43 | } | ||
44 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/HeatProject.cs b/src/tools/WixToolset.HeatTasks/HeatProject.cs new file mode 100644 index 00000000..d54f6ad1 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/HeatProject.cs | |||
@@ -0,0 +1,72 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using Microsoft.Build.Framework; | ||
6 | |||
7 | public sealed class HeatProject : HeatTask | ||
8 | { | ||
9 | private string[] projectOutputGroups; | ||
10 | |||
11 | public string Configuration { get; set; } | ||
12 | |||
13 | public string DirectoryIds { get; set; } | ||
14 | |||
15 | public bool GenerateWixVariables { get; set; } | ||
16 | |||
17 | public string GenerateType { get; set; } | ||
18 | |||
19 | public string MsbuildBinPath { get; set; } | ||
20 | |||
21 | public string Platform { get; set; } | ||
22 | |||
23 | [Required] | ||
24 | public string Project { get; set; } | ||
25 | |||
26 | public string ProjectName { get; set; } | ||
27 | |||
28 | public string[] ProjectOutputGroups | ||
29 | { | ||
30 | get | ||
31 | { | ||
32 | return this.projectOutputGroups; | ||
33 | } | ||
34 | set | ||
35 | { | ||
36 | this.projectOutputGroups = value; | ||
37 | |||
38 | // If it's just one string and it contains semicolons, let's | ||
39 | // split it into separate items. | ||
40 | if (this.projectOutputGroups.Length == 1) | ||
41 | { | ||
42 | this.projectOutputGroups = this.projectOutputGroups[0].Split(new char[] { ';' }); | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | public bool UseToolsVersion { get; set; } | ||
48 | |||
49 | protected override string OperationName => "project"; | ||
50 | |||
51 | protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
52 | { | ||
53 | commandLineBuilder.AppendSwitch(this.OperationName); | ||
54 | commandLineBuilder.AppendFileNameIfNotNull(this.Project); | ||
55 | |||
56 | commandLineBuilder.AppendSwitchIfNotNull("-configuration ", this.Configuration); | ||
57 | commandLineBuilder.AppendSwitchIfNotNull("-directoryid ", this.DirectoryIds); | ||
58 | commandLineBuilder.AppendSwitchIfNotNull("-generate ", this.GenerateType); | ||
59 | commandLineBuilder.AppendSwitchIfNotNull("-msbuildbinpath ", this.MsbuildBinPath); | ||
60 | commandLineBuilder.AppendSwitchIfNotNull("-platform ", this.Platform); | ||
61 | commandLineBuilder.AppendArrayIfNotNull("-pog ", this.ProjectOutputGroups); | ||
62 | commandLineBuilder.AppendSwitchIfNotNull("-projectname ", this.ProjectName); | ||
63 | commandLineBuilder.AppendIfTrue("-wixvar", this.GenerateWixVariables); | ||
64 | |||
65 | #if !NETCOREAPP | ||
66 | commandLineBuilder.AppendIfTrue("-usetoolsversion", this.UseToolsVersion); | ||
67 | #endif | ||
68 | |||
69 | base.BuildCommandLine(commandLineBuilder); | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/HeatTask.cs b/src/tools/WixToolset.HeatTasks/HeatTask.cs new file mode 100644 index 00000000..8942a7e1 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/HeatTask.cs | |||
@@ -0,0 +1,176 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Runtime.InteropServices; | ||
8 | using Microsoft.Build.Framework; | ||
9 | using Microsoft.Build.Utilities; | ||
10 | |||
11 | /// <summary> | ||
12 | /// A base MSBuild task to run the WiX harvester. | ||
13 | /// Specific harvester tasks should extend this class. | ||
14 | /// </summary> | ||
15 | public abstract partial class HeatTask : ToolTask | ||
16 | { | ||
17 | private static readonly string ThisDllPath = new Uri(typeof(HeatTask).Assembly.CodeBase).AbsolutePath; | ||
18 | |||
19 | /// <summary> | ||
20 | /// Gets or sets additional options that are appended the the tool command-line. | ||
21 | /// </summary> | ||
22 | /// <remarks> | ||
23 | /// This allows the task to support extended options in the tool which are not | ||
24 | /// explicitly implemented as properties on the task. | ||
25 | /// </remarks> | ||
26 | public string AdditionalOptions { get; set; } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Gets or sets whether to display the logo. | ||
30 | /// </summary> | ||
31 | public bool NoLogo { get; set; } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Gets or sets whether all warnings should be suppressed. | ||
35 | /// </summary> | ||
36 | public bool SuppressAllWarnings { get; set; } | ||
37 | |||
38 | /// <summary> | ||
39 | /// Gets or sets a list of specific warnings to be suppressed. | ||
40 | /// </summary> | ||
41 | public string[] SuppressSpecificWarnings { get; set; } | ||
42 | |||
43 | /// <summary> | ||
44 | /// Gets or sets whether all warnings should be treated as errors. | ||
45 | /// </summary> | ||
46 | public bool TreatWarningsAsErrors { get; set; } | ||
47 | |||
48 | /// <summary> | ||
49 | /// Gets or sets a list of specific warnings to treat as errors. | ||
50 | /// </summary> | ||
51 | public string[] TreatSpecificWarningsAsErrors { get; set; } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Gets or sets whether to display verbose output. | ||
55 | /// </summary> | ||
56 | public bool VerboseOutput { get; set; } | ||
57 | |||
58 | public bool AutogenerateGuids { get; set; } | ||
59 | |||
60 | public bool GenerateGuidsNow { get; set; } | ||
61 | |||
62 | [Required] | ||
63 | [Output] | ||
64 | public ITaskItem OutputFile { get; set; } | ||
65 | |||
66 | public bool SuppressFragments { get; set; } | ||
67 | |||
68 | public bool SuppressUniqueIds { get; set; } | ||
69 | |||
70 | public string[] Transforms { get; set; } | ||
71 | |||
72 | protected sealed override string ToolName => "heat.exe"; | ||
73 | |||
74 | /// <summary> | ||
75 | /// Gets the name of the heat operation performed by the task. | ||
76 | /// </summary> | ||
77 | /// <remarks>This is the first parameter passed on the heat.exe command-line.</remarks> | ||
78 | /// <value>The name of the heat operation performed by the task.</value> | ||
79 | protected abstract string OperationName { get; } | ||
80 | |||
81 | private string ToolFullPath | ||
82 | { | ||
83 | get | ||
84 | { | ||
85 | if (String.IsNullOrEmpty(this.ToolPath)) | ||
86 | { | ||
87 | return Path.Combine(Path.GetDirectoryName(ThisDllPath), this.ToolExe); | ||
88 | } | ||
89 | |||
90 | return Path.Combine(this.ToolPath, this.ToolExe); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// Get the path to the executable. | ||
96 | /// </summary> | ||
97 | /// <remarks> | ||
98 | /// ToolTask only calls GenerateFullPathToTool when the ToolPath property is not set. | ||
99 | /// WiX never sets the ToolPath property, but the user can through $(HeatToolDir). | ||
100 | /// If we return only a file name, ToolTask will search the system paths for it. | ||
101 | /// </remarks> | ||
102 | protected sealed override string GenerateFullPathToTool() | ||
103 | { | ||
104 | #if NETCOREAPP | ||
105 | // If we're not using heat.exe, use dotnet.exe to exec heat.dll. | ||
106 | // See this.GenerateCommandLine() where "exec heat.dll" is added. | ||
107 | if (!IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) | ||
108 | { | ||
109 | return DotnetFullPath; | ||
110 | } | ||
111 | |||
112 | return toolFullPath; | ||
113 | #else | ||
114 | return this.ToolFullPath; | ||
115 | #endif | ||
116 | } | ||
117 | |||
118 | protected sealed override string GenerateCommandLineCommands() | ||
119 | { | ||
120 | var commandLineBuilder = new WixCommandLineBuilder(); | ||
121 | |||
122 | #if NETCOREAPP | ||
123 | // If we're using dotnet.exe as the target executable, see this.GenerateFullPathToTool(), | ||
124 | // then add "exec heat.dll" to the beginning of the command-line. | ||
125 | if (!IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) | ||
126 | { | ||
127 | //commandLineBuilder.AppendSwitchIfNotNull("exec ", toolFullPath); | ||
128 | commandLineBuilder.AppendSwitch($"exec \"{toolFullPath}\""); | ||
129 | } | ||
130 | #endif | ||
131 | |||
132 | this.BuildCommandLine(commandLineBuilder); | ||
133 | return commandLineBuilder.ToString(); | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Builds a command line from options in this task. | ||
138 | /// </summary> | ||
139 | protected virtual void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
140 | { | ||
141 | commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo); | ||
142 | commandLineBuilder.AppendArrayIfNotNull("-sw", this.SuppressSpecificWarnings); | ||
143 | commandLineBuilder.AppendIfTrue("-sw", this.SuppressAllWarnings); | ||
144 | commandLineBuilder.AppendIfTrue("-v", this.VerboseOutput); | ||
145 | commandLineBuilder.AppendArrayIfNotNull("-wx", this.TreatSpecificWarningsAsErrors); | ||
146 | commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); | ||
147 | |||
148 | commandLineBuilder.AppendIfTrue("-ag", this.AutogenerateGuids); | ||
149 | commandLineBuilder.AppendIfTrue("-gg", this.GenerateGuidsNow); | ||
150 | commandLineBuilder.AppendIfTrue("-sfrag", this.SuppressFragments); | ||
151 | commandLineBuilder.AppendIfTrue("-suid", this.SuppressUniqueIds); | ||
152 | commandLineBuilder.AppendArrayIfNotNull("-t ", this.Transforms); | ||
153 | commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions); | ||
154 | commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile); | ||
155 | } | ||
156 | |||
157 | #if NETCOREAPP | ||
158 | private static readonly string DotnetFullPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; | ||
159 | |||
160 | private static bool IsSelfExecutable(string proposedToolFullPath, out string toolFullPath) | ||
161 | { | ||
162 | var toolFullPathWithoutExtension = Path.Combine(Path.GetDirectoryName(proposedToolFullPath), Path.GetFileNameWithoutExtension(proposedToolFullPath)); | ||
163 | var exeExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : String.Empty; | ||
164 | var exeToolFullPath = $"{toolFullPathWithoutExtension}{exeExtension}"; | ||
165 | if (File.Exists(exeToolFullPath)) | ||
166 | { | ||
167 | toolFullPath = exeToolFullPath; | ||
168 | return true; | ||
169 | } | ||
170 | |||
171 | toolFullPath = $"{toolFullPathWithoutExtension}.dll"; | ||
172 | return false; | ||
173 | } | ||
174 | #endif | ||
175 | } | ||
176 | } | ||
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 | |||
3 | namespace 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 | } | ||
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 | |||
3 | namespace 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 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/RefreshTask.cs b/src/tools/WixToolset.HeatTasks/RefreshTask.cs new file mode 100644 index 00000000..0b378272 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/RefreshTask.cs | |||
@@ -0,0 +1,59 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Text.RegularExpressions; | ||
7 | using Microsoft.Build.Framework; | ||
8 | using Microsoft.Build.Utilities; | ||
9 | |||
10 | /// <summary> | ||
11 | /// A base MSBuild task to refresh generated files. | ||
12 | /// </summary> | ||
13 | public abstract class RefreshTask : Task | ||
14 | { | ||
15 | private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]"); | ||
16 | private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}"); // non 'words' and assorted valid characters | ||
17 | |||
18 | /// <summary>Metadata key name to turn off harvesting of project references.</summary> | ||
19 | protected const string DoNotHarvest = "DoNotHarvest"; | ||
20 | |||
21 | /// <summary> | ||
22 | /// The list of files to generate. | ||
23 | /// </summary> | ||
24 | [Required] | ||
25 | public ITaskItem[] GeneratedFiles { get; set; } | ||
26 | |||
27 | /// <summary> | ||
28 | /// All the project references in the project. | ||
29 | /// </summary> | ||
30 | [Required] | ||
31 | public ITaskItem[] ProjectReferencePaths { get; set; } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Return an identifier based on passed file/directory name | ||
35 | /// </summary> | ||
36 | /// <param name="name">File/directory name to generate identifer from</param> | ||
37 | /// <returns>A version of the name that is a legal identifier.</returns> | ||
38 | /// <remarks>This is duplicated from WiX's Common class.</remarks> | ||
39 | protected static string GetIdentifierFromName(string name) | ||
40 | { | ||
41 | var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". | ||
42 | |||
43 | // MSI identifiers must begin with an alphabetic character or an | ||
44 | // underscore. Prefix all other values with an underscore. | ||
45 | if (AddPrefix.IsMatch(name)) | ||
46 | { | ||
47 | result = String.Concat("_", result); | ||
48 | } | ||
49 | |||
50 | return result; | ||
51 | } | ||
52 | |||
53 | protected static string GetMetadataOrDefault(ITaskItem item, string metadataName, string defaultValue) | ||
54 | { | ||
55 | var value = item.GetMetadata(metadataName); | ||
56 | return String.IsNullOrWhiteSpace(value) ? defaultValue : value; | ||
57 | } | ||
58 | } | ||
59 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs b/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs new file mode 100644 index 00000000..c3989902 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs | |||
@@ -0,0 +1,56 @@ | |||
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 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using Microsoft.Build.Utilities; | ||
8 | |||
9 | /// <summary> | ||
10 | /// Helper class for appending the command line arguments. | ||
11 | /// </summary> | ||
12 | public class WixCommandLineBuilder : CommandLineBuilder | ||
13 | { | ||
14 | /// <summary> | ||
15 | /// Append a switch to the command line if the condition is true. | ||
16 | /// </summary> | ||
17 | /// <param name="switchName">Switch to append.</param> | ||
18 | /// <param name="condition">Condition specified by the user.</param> | ||
19 | public void AppendIfTrue(string switchName, bool condition) | ||
20 | { | ||
21 | if (condition) | ||
22 | { | ||
23 | this.AppendSwitch(switchName); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | /// <summary> | ||
28 | /// Append a switch to the command line if any values in the array have been specified. | ||
29 | /// </summary> | ||
30 | /// <param name="switchName">Switch to append.</param> | ||
31 | /// <param name="values">Values specified by the user.</param> | ||
32 | public void AppendArrayIfNotNull(string switchName, IEnumerable<string> values) | ||
33 | { | ||
34 | if (values != null) | ||
35 | { | ||
36 | foreach (var value in values) | ||
37 | { | ||
38 | this.AppendSwitchIfNotNull(switchName, value); | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /// <summary> | ||
44 | /// Append arbitrary text to the command-line if specified. | ||
45 | /// </summary> | ||
46 | /// <param name="textToAppend">Text to append.</param> | ||
47 | public void AppendTextIfNotNull(string textToAppend) | ||
48 | { | ||
49 | if (!String.IsNullOrWhiteSpace(textToAppend)) | ||
50 | { | ||
51 | this.AppendSpaceIfNotEmpty(); | ||
52 | this.AppendTextUnquoted(textToAppend); | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
diff --git a/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj b/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj new file mode 100644 index 00000000..ea52bdfa --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj | |||
@@ -0,0 +1,17 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- 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. --> | ||
3 | |||
4 | <Project Sdk="Microsoft.NET.Sdk"> | ||
5 | <PropertyGroup> | ||
6 | <TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks> | ||
7 | <Title>WiX Toolset Heat MSBuild Tasks</Title> | ||
8 | <DebugType>embedded</DebugType> | ||
9 | <PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
10 | <!-- https://github.com/Microsoft/msbuild/issues/2360 --> | ||
11 | <PlatformTarget>AnyCPU</PlatformTarget> | ||
12 | </PropertyGroup> | ||
13 | |||
14 | <ItemGroup> | ||
15 | <PackageReference Include="Microsoft.Build.Tasks.Core" /> | ||
16 | </ItemGroup> | ||
17 | </Project> | ||