aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/Light.cs
blob: b7d0b4f7d8917d16945dca8407b76e57dcd40715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
// 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.

namespace WixToolset.BuildTasks
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.IO;
    using System.Text;

    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;

    /// <summary>
    /// An MSBuild task to run the WiX linker.
    /// </summary>
    public sealed class Light : WixToolTask
    {
        private const string LightToolName = "Light.exe";

        private string additionalCub;
        private bool allowIdenticalRows;
        private bool allowUnresolvedReferences;
        private string[] baseInputPaths;
        private ITaskItem[] bindInputPaths;
        private bool backwardsCompatibleGuidGeneration;
        private bool bindFiles;
        private ITaskItem builtOutputsFile;
        private string cabinetCachePath;
        private int cabinetCreationThreadCount = WixCommandLineBuilder.Unspecified;
        private ITaskItem contentsFile;
        private string cultures;
        private string customBinder;
        private string defaultCompressionLevel;
        private ITaskItem[] extensions;
        private string[] ices;
        private bool leaveTemporaryFiles;
        private ITaskItem[] localizationFiles;
        private ITaskItem[] objectFiles;
        private bool outputAsXml;
        private ITaskItem outputsFile;
        private ITaskItem outputFile;
        private ITaskItem pdbOutputFile;
        private ITaskItem wixProjectFile;
        private bool pedantic;
        private bool reuseCabinetCache;
        private bool suppressAclReset;
        private bool suppressAssemblies;
        private bool suppressDefaultAdminSequenceActions;
        private bool suppressDefaultAdvSequenceActions;
        private bool suppressDefaultUISequenceActions;
        private bool dropUnrealTables;
        private bool exactAssemblyVersions;
        private bool suppressFileHashAndInfo;
        private bool suppressFiles;
        private bool suppressIntermediateFileVersionMatching;
        private string[] suppressIces;
        private bool suppressLayout;
        private bool suppressLocalization;
        private bool suppressMsiAssemblyTableProcessing;
        private bool suppressPdbOutput;
        private bool suppressSchemaValidation;
        private bool suppressValidation;
        private bool suppressTagSectionIdAttributeOnTuples;
        private ITaskItem unreferencedSymbolsFile;
        private string[] wixVariables;
        private string extensionDirectory;
        private string[] referencePaths;

        /// <summary>
        /// Creates a new light task.
        /// </summary>
        /// <remarks>
        /// Defaults to running the task as a separate process, instead of in-proc
        /// which is the default for WixToolTasks. This allows the Win32 manifest file
        /// embedded in light.exe to enable reg-free COM interop with mergemod.dll.
        /// </remarks>
        public Light()
        {
        }

        public string AdditionalCub
        {
            get { return this.additionalCub; }
            set { this.additionalCub = value; }
        }

        public bool AllowIdenticalRows
        {
            get { return this.allowIdenticalRows; }
            set { this.allowIdenticalRows = value; }
        }

        public bool AllowUnresolvedReferences
        {
            get { return this.allowUnresolvedReferences; }
            set { this.allowUnresolvedReferences = value; }
        }

        // TODO: remove this property entirely in v4.0
        [Obsolete("Use BindInputPaths instead of BaseInputPaths.")]
        public string[] BaseInputPaths
        {
            get { return this.baseInputPaths; }
            set { this.baseInputPaths = value; }
        }

        public ITaskItem[] BindInputPaths
        {
            get { return this.bindInputPaths; }
            set { this.bindInputPaths = value; }
        }

        public bool BackwardsCompatibleGuidGeneration
        {
            get { return this.backwardsCompatibleGuidGeneration; }
            set { this.backwardsCompatibleGuidGeneration = value; }
        }

        public bool BindFiles
        {
            get { return this.bindFiles; }
            set { this.bindFiles = value; }
        }

        public string CabinetCachePath
        {
            get { return this.cabinetCachePath; }
            set { this.cabinetCachePath = value; }
        }

        public int CabinetCreationThreadCount
        {
            get { return this.cabinetCreationThreadCount; }
            set { this.cabinetCreationThreadCount = value; }
        }

        public ITaskItem BindBuiltOutputsFile
        {
            get { return this.builtOutputsFile; }
            set { this.builtOutputsFile = value; }
        }

        public ITaskItem BindContentsFile
        {
            get { return this.contentsFile; }
            set { this.contentsFile = value; }
        }

        public ITaskItem BindOutputsFile
        {
            get { return this.outputsFile; }
            set { this.outputsFile = value; }
        }

        public string Cultures
        {
            get { return this.cultures; }
            set { this.cultures = value; }
        }

        public string CustomBinder
        {
            get { return this.customBinder; }
            set { this.customBinder = value; }
        }

        public string DefaultCompressionLevel
        {
            get { return this.defaultCompressionLevel; }
            set { this.defaultCompressionLevel = value; }
        }

        public bool DropUnrealTables
        {
            get { return this.dropUnrealTables; }
            set { this.dropUnrealTables = value; }
        }

        public bool ExactAssemblyVersions
        {
            get { return this.exactAssemblyVersions; }
            set { this.exactAssemblyVersions = value; }
        }

        public ITaskItem[] Extensions
        {
            get { return this.extensions; }
            set { this.extensions = value; }
        }

        public string[] Ices
        {
            get { return this.ices; }
            set { this.ices = value; }
        }

        public bool LeaveTemporaryFiles
        {
            get { return this.leaveTemporaryFiles; }
            set { this.leaveTemporaryFiles = value; }
        }

        public ITaskItem[] LocalizationFiles
        {
            get { return this.localizationFiles; }
            set { this.localizationFiles = value; }
        }

        [Required]
        public ITaskItem[] ObjectFiles
        {
            get { return this.objectFiles; }
            set { this.objectFiles = value; }
        }

        public bool OutputAsXml
        {
            get { return this.outputAsXml; }
            set { this.outputAsXml = value; }
        }

        [Required]
        [Output]
        public ITaskItem OutputFile
        {
            get { return this.outputFile; }
            set { this.outputFile = value; }
        }

        [Output]
        public ITaskItem PdbOutputFile
        {
            get { return this.pdbOutputFile; }
            set { this.pdbOutputFile = value; }
        }

        public bool Pedantic
        {
            get { return this.pedantic; }
            set { this.pedantic = value; }
        }

        public bool ReuseCabinetCache
        {
            get { return this.reuseCabinetCache; }
            set { this.reuseCabinetCache = value; }
        }

        public bool SuppressAclReset
        {
            get { return this.suppressAclReset; }
            set { this.suppressAclReset = value; }
        }

        public bool SuppressAssemblies
        {
            get { return this.suppressAssemblies; }
            set { this.suppressAssemblies = value; }
        }

        public bool SuppressDefaultAdminSequenceActions
        {
            get { return this.suppressDefaultAdminSequenceActions; }
            set { this.suppressDefaultAdminSequenceActions = value; }
        }

        public bool SuppressDefaultAdvSequenceActions
        {
            get { return this.suppressDefaultAdvSequenceActions; }
            set { this.suppressDefaultAdvSequenceActions = value; }
        }

        public bool SuppressDefaultUISequenceActions
        {
            get { return this.suppressDefaultUISequenceActions; }
            set { this.suppressDefaultUISequenceActions = value; }
        }

        public bool SuppressFileHashAndInfo
        {
            get { return this.suppressFileHashAndInfo; }
            set { this.suppressFileHashAndInfo = value; }
        }

        public bool SuppressFiles
        {
            get { return this.suppressFiles; }
            set { this.suppressFiles = value; }
        }

        public bool SuppressIntermediateFileVersionMatching
        {
            get { return this.suppressIntermediateFileVersionMatching; }
            set { this.suppressIntermediateFileVersionMatching = value; }
        }

        public string[] SuppressIces
        {
            get { return this.suppressIces; }
            set { this.suppressIces = value; }
        }

        public bool SuppressLayout
        {
            get { return this.suppressLayout; }
            set { this.suppressLayout = value; }
        }

        public bool SuppressLocalization
        {
            get { return this.suppressLocalization; }
            set { this.suppressLocalization = value; }
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
        public bool SuppressMsiAssemblyTableProcessing
        {
            get { return this.suppressMsiAssemblyTableProcessing; }
            set { this.suppressMsiAssemblyTableProcessing = value; }
        }

        public bool SuppressPdbOutput
        {
            get { return this.suppressPdbOutput; }
            set { this.suppressPdbOutput = value; }
        }

        public bool SuppressSchemaValidation
        {
            get { return this.suppressSchemaValidation; }
            set { this.suppressSchemaValidation = value; }
        }

        public bool SuppressValidation
        {
            get { return this.suppressValidation; }
            set { this.suppressValidation = value; }
        }

        public bool SuppressTagSectionIdAttributeOnTuples
        {
            get { return this.suppressTagSectionIdAttributeOnTuples; }
            set { this.suppressTagSectionIdAttributeOnTuples = value; }
        }

        [Output]
        public ITaskItem UnreferencedSymbolsFile
        {
            get { return this.unreferencedSymbolsFile; }
            set { this.unreferencedSymbolsFile = value; }
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
        public ITaskItem WixProjectFile
        {
            get { return this.wixProjectFile; }
            set { this.wixProjectFile = value; }
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
        public string[] WixVariables
        {
            get { return this.wixVariables; }
            set { this.wixVariables = value; }
        }

        public string ExtensionDirectory
        {
            get { return this.extensionDirectory; }
            set { this.extensionDirectory = value; }
        }

        public string[] ReferencePaths
        {
            get { return this.referencePaths; }
            set { this.referencePaths = value; }
        }

        /// <summary>
        /// Get the name of the executable.
        /// </summary>
        /// <remarks>The ToolName is used with the ToolPath to get the location of light.exe.</remarks>
        /// <value>The name of the executable.</value>
        protected override string ToolName
        {
            get { return LightToolName; }
        }

        /// <summary>
        /// Get the path to the executable. 
        /// </summary>
        /// <remarks>GetFullPathToTool is only called when the ToolPath property is not set (see the ToolName remarks above).</remarks>
        /// <returns>The full path to the executable or simply light.exe if it's expected to be in the system path.</returns>
        protected override string GenerateFullPathToTool()
        {
            // If there's not a ToolPath specified, it has to be in the system path.
            if (String.IsNullOrEmpty(this.ToolPath))
            {
                return LightToolName;
            }

            return Path.Combine(Path.GetFullPath(this.ToolPath), LightToolName);
        }

        /// <summary>
        /// Builds a command line from options in this task.
        /// </summary>
        protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
        {
            // Always put the output first so it is easy to find in the log.
            commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
            commandLineBuilder.AppendSwitchIfNotNull("-pdbout ", this.PdbOutputFile);

            base.BuildCommandLine(commandLineBuilder);

            commandLineBuilder.AppendIfTrue("-ai", this.AllowIdenticalRows);
            commandLineBuilder.AppendIfTrue("-au", this.AllowUnresolvedReferences);
            commandLineBuilder.AppendArrayIfNotNull("-b ", this.baseInputPaths);

            if (null != this.BindInputPaths)
            {
                Queue<String> formattedBindInputPaths = new Queue<String>();
                foreach (ITaskItem item in this.BindInputPaths)
                {
                    String formattedPath = string.Empty;
                    String bindName = item.GetMetadata("BindName");
                    if (!String.IsNullOrEmpty(bindName))
                    {
                        formattedPath = String.Concat(bindName, "=", item.GetMetadata("FullPath"));
                    }
                    else
                    {
                        formattedPath = item.GetMetadata("FullPath");
                    }
                    formattedBindInputPaths.Enqueue(formattedPath);
                }
                commandLineBuilder.AppendArrayIfNotNull("-b ", formattedBindInputPaths.ToArray());
            }

            commandLineBuilder.AppendIfTrue("-bcgg", this.BackwardsCompatibleGuidGeneration);
            commandLineBuilder.AppendIfTrue("-bf", this.BindFiles);
            commandLineBuilder.AppendSwitchIfNotNull("-cc ", this.CabinetCachePath);
            commandLineBuilder.AppendIfSpecified("-ct ", this.CabinetCreationThreadCount);
            commandLineBuilder.AppendSwitchIfNotNull("-cub ", this.AdditionalCub);
            commandLineBuilder.AppendSwitchIfNotNull("-cultures:", this.Cultures);
            commandLineBuilder.AppendSwitchIfNotNull("-binder ", this.CustomBinder);
            commandLineBuilder.AppendArrayIfNotNull("-d", this.WixVariables);
            commandLineBuilder.AppendSwitchIfNotNull("-dcl:", this.DefaultCompressionLevel);
            commandLineBuilder.AppendIfTrue("-dut", this.DropUnrealTables);
            commandLineBuilder.AppendIfTrue("-eav", this.ExactAssemblyVersions);
            commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.referencePaths);
            commandLineBuilder.AppendArrayIfNotNull("-ice:", this.Ices);
            commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles);
            commandLineBuilder.AppendIfTrue("-notidy", this.LeaveTemporaryFiles);
            commandLineBuilder.AppendIfTrue("-pedantic", this.Pedantic);
            commandLineBuilder.AppendIfTrue("-reusecab", this.ReuseCabinetCache);
            commandLineBuilder.AppendIfTrue("-sa", this.SuppressAssemblies);
            commandLineBuilder.AppendIfTrue("-sacl", this.SuppressAclReset);
            commandLineBuilder.AppendIfTrue("-sadmin", this.SuppressDefaultAdminSequenceActions);
            commandLineBuilder.AppendIfTrue("-sadv", this.SuppressDefaultAdvSequenceActions);
            commandLineBuilder.AppendArrayIfNotNull("-sice:", this.SuppressIces);
            commandLineBuilder.AppendIfTrue("-sma", this.SuppressMsiAssemblyTableProcessing);
            commandLineBuilder.AppendIfTrue("-sf", this.SuppressFiles);
            commandLineBuilder.AppendIfTrue("-sh", this.SuppressFileHashAndInfo);
            commandLineBuilder.AppendIfTrue("-sl", this.SuppressLayout);
            commandLineBuilder.AppendIfTrue("-sloc", this.SuppressLocalization);
            commandLineBuilder.AppendIfTrue("-spdb", this.SuppressPdbOutput);
            commandLineBuilder.AppendIfTrue("-ss", this.SuppressSchemaValidation);
            commandLineBuilder.AppendIfTrue("-sts", this.SuppressTagSectionIdAttributeOnTuples);
            commandLineBuilder.AppendIfTrue("-sui", this.SuppressDefaultUISequenceActions);
            commandLineBuilder.AppendIfTrue("-sv", this.SuppressIntermediateFileVersionMatching);
            commandLineBuilder.AppendIfTrue("-sval", this.SuppressValidation);
            commandLineBuilder.AppendSwitchIfNotNull("-usf ", this.UnreferencedSymbolsFile);
            commandLineBuilder.AppendIfTrue("-xo", this.OutputAsXml);
            commandLineBuilder.AppendSwitchIfNotNull("-contentsfile ", this.BindContentsFile);
            commandLineBuilder.AppendSwitchIfNotNull("-outputsfile ", this.BindOutputsFile);
            commandLineBuilder.AppendSwitchIfNotNull("-builtoutputsfile ", this.BindBuiltOutputsFile);
            commandLineBuilder.AppendSwitchIfNotNull("-wixprojectfile ", this.WixProjectFile);
            commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);

            List<string> objectFilePaths = AdjustFilePaths(this.objectFiles, this.ReferencePaths);
            commandLineBuilder.AppendFileNamesIfNotNull(objectFilePaths.ToArray(), " ");
        }
    }
}