diff options
author | Rob Mensching <rob@firegiant.com> | 2022-10-12 22:01:55 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-10-14 20:13:50 -0700 |
commit | 07b3d459ea0a45cbef29b98d283edafbab26462a (patch) | |
tree | 1e834882038ba3862f8acb7b60e7a4bfaef793fd /src/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs | |
parent | 5567239a9411aac769a34f2c65b80a523a577ad7 (diff) | |
download | wix-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/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs')
-rw-r--r-- | src/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/src/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs b/src/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs new file mode 100644 index 00000000..152992dd --- /dev/null +++ b/src/internal/WixToolset.BaseBuildTasks.Sources/WixCommandLineBuilder.cs | |||
@@ -0,0 +1,177 @@ | |||
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.BaseBuildTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Globalization; | ||
8 | using System.IO; | ||
9 | |||
10 | using Microsoft.Build.Framework; | ||
11 | using Microsoft.Build.Utilities; | ||
12 | |||
13 | /// <summary> | ||
14 | /// Helper class for appending the command line arguments. | ||
15 | /// </summary> | ||
16 | public class WixCommandLineBuilder : CommandLineBuilder | ||
17 | { | ||
18 | internal const int Unspecified = -1; | ||
19 | |||
20 | /// <summary> | ||
21 | /// Append a switch to the command line if the value has been specified. | ||
22 | /// </summary> | ||
23 | /// <param name="switchName">Switch to append.</param> | ||
24 | /// <param name="value">Value specified by the user.</param> | ||
25 | public void AppendIfSpecified(string switchName, int value) | ||
26 | { | ||
27 | if (value != Unspecified) | ||
28 | { | ||
29 | this.AppendSwitchIfNotNull(switchName, value.ToString(CultureInfo.InvariantCulture)); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Append a switch to the command line if the condition is true. | ||
35 | /// </summary> | ||
36 | /// <param name="switchName">Switch to append.</param> | ||
37 | /// <param name="condition">Condition specified by the user.</param> | ||
38 | public void AppendIfTrue(string switchName, bool condition) | ||
39 | { | ||
40 | if (condition) | ||
41 | { | ||
42 | this.AppendSwitch(switchName); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// Append a switch to the command line if any values in the array have been specified. | ||
48 | /// </summary> | ||
49 | /// <param name="switchName">Switch to append.</param> | ||
50 | /// <param name="values">Values specified by the user.</param> | ||
51 | public void AppendArrayIfNotNull(string switchName, IEnumerable<ITaskItem> values) | ||
52 | { | ||
53 | if (values != null) | ||
54 | { | ||
55 | foreach (ITaskItem value in values) | ||
56 | { | ||
57 | this.AppendSwitchIfNotNull(switchName, value); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Append a switch to the command line if any values in the array have been specified. | ||
64 | /// </summary> | ||
65 | /// <param name="switchName">Switch to append.</param> | ||
66 | /// <param name="values">Values specified by the user.</param> | ||
67 | public void AppendArrayIfNotNull(string switchName, IEnumerable<string> values) | ||
68 | { | ||
69 | if (values != null) | ||
70 | { | ||
71 | foreach (string value in values) | ||
72 | { | ||
73 | this.AppendSwitchIfNotNull(switchName, value); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /// <summary> | ||
79 | /// Build the extensions argument. Each extension is searched in the current folder, user defined search | ||
80 | /// directories (ReferencePath), HintPath, and under Wix Extension Directory in that order. | ||
81 | /// The order of precedence is based off of that described in Microsoft.Common.Targets's SearchPaths | ||
82 | /// property for the ResolveAssemblyReferences task. | ||
83 | /// </summary> | ||
84 | /// <param name="extensions">The list of extensions to include.</param> | ||
85 | /// <param name="wixExtensionDirectory">Evaluated default folder for Wix Extensions</param> | ||
86 | /// <param name="referencePaths">User defined reference directories to search in</param> | ||
87 | public void AppendExtensions(ITaskItem[] extensions, string wixExtensionDirectory, string [] referencePaths) | ||
88 | { | ||
89 | if (extensions == null) | ||
90 | { | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | foreach (ITaskItem extension in extensions) | ||
95 | { | ||
96 | string className = extension.GetMetadata("Class"); | ||
97 | |||
98 | string fileName = Path.GetFileName(extension.ItemSpec); | ||
99 | |||
100 | if (String.IsNullOrEmpty(Path.GetExtension(fileName))) | ||
101 | { | ||
102 | fileName += ".dll"; | ||
103 | } | ||
104 | |||
105 | // First try reference paths | ||
106 | var resolvedPath = FileSearchHelperMethods.SearchFilePaths(referencePaths, fileName); | ||
107 | |||
108 | if (String.IsNullOrEmpty(resolvedPath)) | ||
109 | { | ||
110 | // Now try HintPath | ||
111 | resolvedPath = extension.GetMetadata("HintPath"); | ||
112 | |||
113 | if (!File.Exists(resolvedPath)) | ||
114 | { | ||
115 | // Now try the item itself | ||
116 | resolvedPath = extension.ItemSpec; | ||
117 | |||
118 | if (String.IsNullOrEmpty(Path.GetExtension(resolvedPath))) | ||
119 | { | ||
120 | resolvedPath += ".dll"; | ||
121 | } | ||
122 | |||
123 | if (!File.Exists(resolvedPath)) | ||
124 | { | ||
125 | if (!String.IsNullOrEmpty(wixExtensionDirectory)) | ||
126 | { | ||
127 | // Now try the extension directory | ||
128 | resolvedPath = Path.Combine(wixExtensionDirectory, Path.GetFileName(resolvedPath)); | ||
129 | } | ||
130 | |||
131 | if (!File.Exists(resolvedPath)) | ||
132 | { | ||
133 | // Extension wasn't found, just set it to the extension name passed in | ||
134 | resolvedPath = extension.ItemSpec; | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | if (String.IsNullOrEmpty(className)) | ||
141 | { | ||
142 | this.AppendSwitchIfNotNull("-ext ", resolvedPath); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | this.AppendSwitchIfNotNull("-ext ", className + ", " + resolvedPath); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// Append arbitrary text to the command-line if specified. | ||
153 | /// </summary> | ||
154 | /// <param name="textToAppend">Text to append.</param> | ||
155 | public void AppendTextIfNotNull(string textToAppend) | ||
156 | { | ||
157 | if (!String.IsNullOrEmpty(textToAppend)) | ||
158 | { | ||
159 | this.AppendSpaceIfNotEmpty(); | ||
160 | this.AppendTextUnquoted(textToAppend); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | /// <summary> | ||
165 | /// Append arbitrary text to the command-line if specified. | ||
166 | /// </summary> | ||
167 | /// <param name="textToAppend">Text to append.</param> | ||
168 | public void AppendTextIfNotWhitespace(string textToAppend) | ||
169 | { | ||
170 | if (!String.IsNullOrWhiteSpace(textToAppend)) | ||
171 | { | ||
172 | this.AppendSpaceIfNotEmpty(); | ||
173 | this.AppendTextUnquoted(textToAppend); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | } | ||