aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-10-12 22:01:55 -0700
committerRob Mensching <rob@firegiant.com>2022-10-14 20:13:50 -0700
commit07b3d459ea0a45cbef29b98d283edafbab26462a (patch)
tree1e834882038ba3862f8acb7b60e7a4bfaef793fd /src/tools
parent5567239a9411aac769a34f2c65b80a523a577ad7 (diff)
downloadwix-07b3d459ea0a45cbef29b98d283edafbab26462a.tar.gz
wix-07b3d459ea0a45cbef29b98d283edafbab26462a.tar.bz2
wix-07b3d459ea0a45cbef29b98d283edafbab26462a.zip
Normalize ToolsetTask implementation to call wix.exe and heat.exe
Share the ToolsetTask implementation that can find .NET Core and .NET Framework with multiple architectures. Fixes 6951
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/WixToolset.HeatTasks/HeatDirectory.cs1
-rw-r--r--src/tools/WixToolset.HeatTasks/HeatFile.cs1
-rw-r--r--src/tools/WixToolset.HeatTasks/HeatProject.cs1
-rw-r--r--src/tools/WixToolset.HeatTasks/HeatTask.cs139
-rw-r--r--src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs56
-rw-r--r--src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj1
6 files changed, 9 insertions, 190 deletions
diff --git a/src/tools/WixToolset.HeatTasks/HeatDirectory.cs b/src/tools/WixToolset.HeatTasks/HeatDirectory.cs
index 8a169055..14a8acfa 100644
--- a/src/tools/WixToolset.HeatTasks/HeatDirectory.cs
+++ b/src/tools/WixToolset.HeatTasks/HeatDirectory.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.HeatTasks 3namespace WixToolset.HeatTasks
4{ 4{
5 using Microsoft.Build.Framework; 5 using Microsoft.Build.Framework;
6 using WixToolset.BaseBuildTasks;
6 7
7 public sealed class HeatDirectory : HeatTask 8 public sealed class HeatDirectory : HeatTask
8 { 9 {
diff --git a/src/tools/WixToolset.HeatTasks/HeatFile.cs b/src/tools/WixToolset.HeatTasks/HeatFile.cs
index 83cbc4d1..b39de7da 100644
--- a/src/tools/WixToolset.HeatTasks/HeatFile.cs
+++ b/src/tools/WixToolset.HeatTasks/HeatFile.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.HeatTasks 3namespace WixToolset.HeatTasks
4{ 4{
5 using Microsoft.Build.Framework; 5 using Microsoft.Build.Framework;
6 using WixToolset.BaseBuildTasks;
6 7
7 public sealed class HeatFile : HeatTask 8 public sealed class HeatFile : HeatTask
8 { 9 {
diff --git a/src/tools/WixToolset.HeatTasks/HeatProject.cs b/src/tools/WixToolset.HeatTasks/HeatProject.cs
index d54f6ad1..998c14ab 100644
--- a/src/tools/WixToolset.HeatTasks/HeatProject.cs
+++ b/src/tools/WixToolset.HeatTasks/HeatProject.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.HeatTasks 3namespace WixToolset.HeatTasks
4{ 4{
5 using Microsoft.Build.Framework; 5 using Microsoft.Build.Framework;
6 using WixToolset.BaseBuildTasks;
6 7
7 public sealed class HeatProject : HeatTask 8 public sealed class HeatProject : HeatTask
8 { 9 {
diff --git a/src/tools/WixToolset.HeatTasks/HeatTask.cs b/src/tools/WixToolset.HeatTasks/HeatTask.cs
index 6b7b9399..cad6635b 100644
--- a/src/tools/WixToolset.HeatTasks/HeatTask.cs
+++ b/src/tools/WixToolset.HeatTasks/HeatTask.cs
@@ -2,64 +2,15 @@
2 2
3namespace WixToolset.HeatTasks 3namespace WixToolset.HeatTasks
4{ 4{
5 using System;
6 using System.IO;
7 using System.Runtime.InteropServices;
8 using Microsoft.Build.Framework; 5 using Microsoft.Build.Framework;
9 using Microsoft.Build.Utilities; 6 using WixToolset.BaseBuildTasks;
10 7
11 /// <summary> 8 /// <summary>
12 /// A base MSBuild task to run the WiX harvester. 9 /// A base MSBuild task to run the WiX harvester.
13 /// Specific harvester tasks should extend this class. 10 /// Specific harvester tasks should extend this class.
14 /// </summary> 11 /// </summary>
15 public abstract partial class HeatTask : ToolTask 12 public abstract partial class HeatTask : BaseToolsetTask
16 { 13 {
17#if NETFRAMEWORK
18 private static readonly string ThisDllPath = new Uri(typeof(HeatTask).Assembly.CodeBase).AbsolutePath;
19#else
20 private static readonly string ThisDllPath = typeof(HeatTask).Assembly.Location;
21#endif
22
23
24 /// <summary>
25 /// Gets or sets additional options that are appended the the tool command-line.
26 /// </summary>
27 /// <remarks>
28 /// This allows the task to support extended options in the tool which are not
29 /// explicitly implemented as properties on the task.
30 /// </remarks>
31 public string AdditionalOptions { get; set; }
32
33 /// <summary>
34 /// Gets or sets whether to display the logo.
35 /// </summary>
36 public bool NoLogo { get; set; }
37
38 /// <summary>
39 /// Gets or sets whether all warnings should be suppressed.
40 /// </summary>
41 public bool SuppressAllWarnings { get; set; }
42
43 /// <summary>
44 /// Gets or sets a list of specific warnings to be suppressed.
45 /// </summary>
46 public string[] SuppressSpecificWarnings { get; set; }
47
48 /// <summary>
49 /// Gets or sets whether all warnings should be treated as errors.
50 /// </summary>
51 public bool TreatWarningsAsErrors { get; set; }
52
53 /// <summary>
54 /// Gets or sets a list of specific warnings to treat as errors.
55 /// </summary>
56 public string[] TreatSpecificWarningsAsErrors { get; set; }
57
58 /// <summary>
59 /// Gets or sets whether to display verbose output.
60 /// </summary>
61 public bool VerboseOutput { get; set; }
62
63 public bool AutogenerateGuids { get; set; } 14 public bool AutogenerateGuids { get; set; }
64 15
65 public bool GenerateGuidsNow { get; set; } 16 public bool GenerateGuidsNow { get; set; }
@@ -74,8 +25,6 @@ namespace WixToolset.HeatTasks
74 25
75 public string[] Transforms { get; set; } 26 public string[] Transforms { get; set; }
76 27
77 protected sealed override string ToolName => "heat.exe";
78
79 /// <summary> 28 /// <summary>
80 /// Gets the name of the heat operation performed by the task. 29 /// Gets the name of the heat operation performed by the task.
81 /// </summary> 30 /// </summary>
@@ -83,99 +32,21 @@ namespace WixToolset.HeatTasks
83 /// <value>The name of the heat operation performed by the task.</value> 32 /// <value>The name of the heat operation performed by the task.</value>
84 protected abstract string OperationName { get; } 33 protected abstract string OperationName { get; }
85 34
86 private string ToolFullPath 35 protected sealed override string ToolName => "heat.exe";
87 {
88 get
89 {
90 if (String.IsNullOrEmpty(this.ToolPath))
91 {
92 return Path.Combine(Path.GetDirectoryName(ThisDllPath), this.ToolExe);
93 }
94
95 return Path.Combine(this.ToolPath, this.ToolExe);
96 }
97 }
98
99 /// <summary>
100 /// Get the path to the executable.
101 /// </summary>
102 /// <remarks>
103 /// ToolTask only calls GenerateFullPathToTool when the ToolPath property is not set.
104 /// WiX never sets the ToolPath property, but the user can through $(HeatToolDir).
105 /// If we return only a file name, ToolTask will search the system paths for it.
106 /// </remarks>
107 protected sealed override string GenerateFullPathToTool()
108 {
109#if NETCOREAPP
110 // If we're not using heat.exe, use dotnet.exe to exec heat.dll.
111 // See this.GenerateCommandLine() where "exec heat.dll" is added.
112 if (!IsSelfExecutable(this.ToolFullPath, out var toolFullPath))
113 {
114 return DotnetFullPath;
115 }
116
117 return toolFullPath;
118#else
119 return this.ToolFullPath;
120#endif
121 }
122
123 protected sealed override string GenerateCommandLineCommands()
124 {
125 var commandLineBuilder = new WixCommandLineBuilder();
126
127#if NETCOREAPP
128 // If we're using dotnet.exe as the target executable, see this.GenerateFullPathToTool(),
129 // then add "exec heat.dll" to the beginning of the command-line.
130 if (!IsSelfExecutable(this.ToolFullPath, out var toolFullPath))
131 {
132 //commandLineBuilder.AppendSwitchIfNotNull("exec ", toolFullPath);
133 commandLineBuilder.AppendSwitch($"exec \"{toolFullPath}\"");
134 }
135#endif
136
137 this.BuildCommandLine(commandLineBuilder);
138 return commandLineBuilder.ToString();
139 }
140 36
141 /// <summary> 37 /// <summary>
142 /// Builds a command line from options in this task. 38 /// Builds a command line from options in this task.
143 /// </summary> 39 /// </summary>
144 protected virtual void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) 40 protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
145 { 41 {
146 commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo); 42 base.BuildCommandLine(commandLineBuilder);
147 commandLineBuilder.AppendArrayIfNotNull("-sw", this.SuppressSpecificWarnings);
148 commandLineBuilder.AppendIfTrue("-sw", this.SuppressAllWarnings);
149 commandLineBuilder.AppendIfTrue("-v", this.VerboseOutput);
150 commandLineBuilder.AppendArrayIfNotNull("-wx", this.TreatSpecificWarningsAsErrors);
151 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors);
152 43
153 commandLineBuilder.AppendIfTrue("-ag", this.AutogenerateGuids); 44 commandLineBuilder.AppendIfTrue("-ag", this.AutogenerateGuids);
154 commandLineBuilder.AppendIfTrue("-gg", this.GenerateGuidsNow); 45 commandLineBuilder.AppendIfTrue("-gg", this.GenerateGuidsNow);
155 commandLineBuilder.AppendIfTrue("-sfrag", this.SuppressFragments); 46 commandLineBuilder.AppendIfTrue("-sfrag", this.SuppressFragments);
156 commandLineBuilder.AppendIfTrue("-suid", this.SuppressUniqueIds); 47 commandLineBuilder.AppendIfTrue("-suid", this.SuppressUniqueIds);
157 commandLineBuilder.AppendArrayIfNotNull("-t ", this.Transforms); 48 commandLineBuilder.AppendArrayIfNotNull("-t ", this.Transforms);
158 commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
159 commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile); 49 commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
160 } 50 }
161
162#if NETCOREAPP
163 private static readonly string DotnetFullPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
164
165 private static bool IsSelfExecutable(string proposedToolFullPath, out string toolFullPath)
166 {
167 var toolFullPathWithoutExtension = Path.Combine(Path.GetDirectoryName(proposedToolFullPath), Path.GetFileNameWithoutExtension(proposedToolFullPath));
168 var exeExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : String.Empty;
169 var exeToolFullPath = $"{toolFullPathWithoutExtension}{exeExtension}";
170 if (File.Exists(exeToolFullPath))
171 {
172 toolFullPath = exeToolFullPath;
173 return true;
174 }
175
176 toolFullPath = $"{toolFullPathWithoutExtension}.dll";
177 return false;
178 }
179#endif
180 } 51 }
181} 52}
diff --git a/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs b/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs
deleted file mode 100644
index c3989902..00000000
--- a/src/tools/WixToolset.HeatTasks/WixCommandLineBuilder.cs
+++ /dev/null
@@ -1,56 +0,0 @@
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.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
index 21fb419c..a8538d9e 100644
--- a/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj
+++ b/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj
@@ -12,5 +12,6 @@
12 12
13 <ItemGroup> 13 <ItemGroup>
14 <PackageReference Include="Microsoft.Build.Tasks.Core" /> 14 <PackageReference Include="Microsoft.Build.Tasks.Core" />
15 <PackageReference Include="WixToolset.BaseBuildTasks.Sources" />
15 </ItemGroup> 16 </ItemGroup>
16</Project> 17</Project>