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/heat/VSHeatExtension.cs | |
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/heat/VSHeatExtension.cs')
-rw-r--r-- | src/tools/heat/VSHeatExtension.cs | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/tools/heat/VSHeatExtension.cs b/src/tools/heat/VSHeatExtension.cs new file mode 100644 index 00000000..d31cd25a --- /dev/null +++ b/src/tools/heat/VSHeatExtension.cs | |||
@@ -0,0 +1,229 @@ | |||
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.Harvesters | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections; | ||
7 | using WixToolset.Data; | ||
8 | using WixToolset.Harvesters.Data; | ||
9 | using WixToolset.Harvesters.Extensibility; | ||
10 | |||
11 | /// <summary> | ||
12 | /// Defines generated element types. | ||
13 | /// </summary> | ||
14 | public enum GenerateType | ||
15 | { | ||
16 | /// <summary>Generate Components.</summary> | ||
17 | Components, | ||
18 | |||
19 | /// <summary>Generate a Container with Payloads.</summary> | ||
20 | Container, | ||
21 | |||
22 | /// <summary>Generate a Bundle PackageGroups.</summary> | ||
23 | PackageGroup, | ||
24 | |||
25 | /// <summary>Generate a PayloadGroup with Payloads.</summary> | ||
26 | PayloadGroup, | ||
27 | } | ||
28 | |||
29 | /// <summary> | ||
30 | /// VS-related extensions for the WiX Toolset Harvester application. | ||
31 | /// </summary> | ||
32 | public sealed class VSHeatExtension : BaseHeatExtension | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Gets the supported command line types for this extension. | ||
36 | /// </summary> | ||
37 | /// <value>The supported command line types for this extension.</value> | ||
38 | public override HeatCommandLineOption[] CommandLineTypes | ||
39 | { | ||
40 | get | ||
41 | { | ||
42 | return new HeatCommandLineOption[] | ||
43 | { | ||
44 | new HeatCommandLineOption("project", "harvest outputs of a VS project"), | ||
45 | new HeatCommandLineOption("-configuration", "configuration to set when harvesting the project"), | ||
46 | new HeatCommandLineOption("-directoryid", "overridden directory id for generated directory elements"), | ||
47 | new HeatCommandLineOption("-generate", Environment.NewLine + | ||
48 | " specify what elements to generate, one of:" + Environment.NewLine + | ||
49 | " components, container, payloadgroup, packagegroup" + Environment.NewLine + | ||
50 | " (default is components)"), | ||
51 | new HeatCommandLineOption("-msbuildbinpath", "msbuild bin directory path"), | ||
52 | new HeatCommandLineOption("-platform", "platform to set when harvesting the project"), | ||
53 | new HeatCommandLineOption("-pog", Environment.NewLine + | ||
54 | " specify output group of VS project, one of:" + Environment.NewLine + | ||
55 | " " + String.Join(",", VSProjectHarvester.GetOutputGroupNames()) + Environment.NewLine + | ||
56 | " This option may be repeated for multiple output groups."), | ||
57 | new HeatCommandLineOption("-projectname", "overridden project name to use in variables"), | ||
58 | new HeatCommandLineOption("-usetoolsversion", "ignore msbuildbinpath if project specifies known msbuild version"), | ||
59 | new HeatCommandLineOption("-wixvar", "generate binder variables instead of preprocessor variables"), | ||
60 | }; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Parse the command line options for this extension. | ||
66 | /// </summary> | ||
67 | /// <param name="type">The active harvester type.</param> | ||
68 | /// <param name="args">The option arguments.</param> | ||
69 | public override void ParseOptions(string type, string[] args) | ||
70 | { | ||
71 | if ("project" == type) | ||
72 | { | ||
73 | string[] allOutputGroups = VSProjectHarvester.GetOutputGroupNames(); | ||
74 | bool suppressUniqueId = false; | ||
75 | bool generateWixVars = false; | ||
76 | bool useToolsVersion = false; | ||
77 | GenerateType generateType = GenerateType.Components; | ||
78 | string directoryIds = null; | ||
79 | string msbuildBinPath = null; | ||
80 | string projectName = null; | ||
81 | string configuration = null; | ||
82 | string platform = null; | ||
83 | ArrayList outputGroups = new ArrayList(); | ||
84 | |||
85 | for (int i = 0; i < args.Length; i++) | ||
86 | { | ||
87 | if ("-configuration" == args[i]) | ||
88 | { | ||
89 | configuration = args[++i]; | ||
90 | } | ||
91 | else if ("-directoryid" == args[i]) | ||
92 | { | ||
93 | if (!IsValidArg(args, ++i)) | ||
94 | { | ||
95 | throw new WixException(HarvesterErrors.InvalidDirectoryId(args[i])); | ||
96 | } | ||
97 | |||
98 | directoryIds = args[i]; | ||
99 | } | ||
100 | else if ("-generate" == args[i]) | ||
101 | { | ||
102 | if (!IsValidArg(args, ++i)) | ||
103 | { | ||
104 | throw new WixException(HarvesterErrors.InvalidProjectOutputType(args[i])); | ||
105 | } | ||
106 | |||
107 | string genType = args[i].ToUpperInvariant(); | ||
108 | switch(genType) | ||
109 | { | ||
110 | case "CONTAINER": | ||
111 | generateType = GenerateType.Container; | ||
112 | break; | ||
113 | case "COMPONENTS": | ||
114 | generateType = GenerateType.Components; | ||
115 | break; | ||
116 | case "PACKAGEGROUP": | ||
117 | generateType = GenerateType.PackageGroup; | ||
118 | break; | ||
119 | case "PAYLOADGROUP": | ||
120 | generateType = GenerateType.PayloadGroup; | ||
121 | break; | ||
122 | default: | ||
123 | throw new WixException(HarvesterErrors.InvalidProjectOutputType(genType)); | ||
124 | } | ||
125 | } | ||
126 | else if ("-msbuildbinpath" == args[i]) | ||
127 | { | ||
128 | if (!IsValidArg(args, ++i)) | ||
129 | { | ||
130 | throw new WixException(HarvesterErrors.ArgumentRequiresValue(args[i-1])); | ||
131 | } | ||
132 | |||
133 | msbuildBinPath = args[i]; | ||
134 | } | ||
135 | else if ("-platform" == args[i]) | ||
136 | { | ||
137 | platform = args[++i]; | ||
138 | } | ||
139 | else if ("-pog" == args[i]) | ||
140 | { | ||
141 | if (!IsValidArg(args, ++i)) | ||
142 | { | ||
143 | throw new WixException(HarvesterErrors.InvalidOutputGroup(args[i])); | ||
144 | } | ||
145 | |||
146 | string pogName = args[i]; | ||
147 | bool found = false; | ||
148 | foreach (string availableOutputGroup in allOutputGroups) | ||
149 | { | ||
150 | if (String.Equals(pogName, availableOutputGroup, StringComparison.Ordinal)) | ||
151 | { | ||
152 | outputGroups.Add(availableOutputGroup); | ||
153 | found = true; | ||
154 | break; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | if (!found) | ||
159 | { | ||
160 | throw new WixException(HarvesterErrors.InvalidOutputGroup(pogName)); | ||
161 | } | ||
162 | } | ||
163 | else if (args[i].StartsWith("-pog:", StringComparison.Ordinal)) | ||
164 | { | ||
165 | this.Core.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("pog:", "pog")); | ||
166 | |||
167 | string pogName = args[i].Substring(5); | ||
168 | bool found = false; | ||
169 | foreach (string availableOutputGroup in allOutputGroups) | ||
170 | { | ||
171 | if (String.Equals(pogName, availableOutputGroup, StringComparison.Ordinal)) | ||
172 | { | ||
173 | outputGroups.Add(availableOutputGroup); | ||
174 | found = true; | ||
175 | break; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | if (!found) | ||
180 | { | ||
181 | throw new WixException(HarvesterErrors.InvalidOutputGroup(pogName)); | ||
182 | } | ||
183 | } | ||
184 | else if ("-projectname" == args[i]) | ||
185 | { | ||
186 | if (!IsValidArg(args, ++i)) | ||
187 | { | ||
188 | throw new WixException(HarvesterErrors.InvalidProjectName(args[i])); | ||
189 | } | ||
190 | |||
191 | projectName = args[i]; | ||
192 | } | ||
193 | else if ("-suid" == args[i]) | ||
194 | { | ||
195 | suppressUniqueId = true; | ||
196 | } | ||
197 | else if ("-usetoolsversion" == args[i]) | ||
198 | { | ||
199 | useToolsVersion = true; | ||
200 | } | ||
201 | else if ("-wixvar" == args[i]) | ||
202 | { | ||
203 | generateWixVars = true; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | if (outputGroups.Count == 0) | ||
208 | { | ||
209 | throw new WixException(HarvesterErrors.NoOutputGroupSpecified()); | ||
210 | } | ||
211 | |||
212 | VSProjectHarvester harvester = new VSProjectHarvester( | ||
213 | (string[]) outputGroups.ToArray(typeof(string))); | ||
214 | |||
215 | harvester.SetUniqueIdentifiers = !suppressUniqueId; | ||
216 | harvester.GenerateWixVars = generateWixVars; | ||
217 | harvester.GenerateType = generateType; | ||
218 | harvester.DirectoryIds = directoryIds; | ||
219 | harvester.MsbuildBinPath = msbuildBinPath; | ||
220 | harvester.ProjectName = projectName; | ||
221 | harvester.Configuration = configuration; | ||
222 | harvester.Platform = platform; | ||
223 | harvester.UseToolsVersion = String.IsNullOrEmpty(msbuildBinPath) || useToolsVersion; | ||
224 | |||
225 | this.Core.Harvester.Extension = harvester; | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||