main
cs 128 lines 4.71 KB
Raw
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.BuildTasks
4 {
5 using System;
6 using System.Collections.Generic;
7 using Microsoft.Build.Framework;
8 using WixToolset.BaseBuildTasks;
9
10 /// <summary>
11 /// An MSBuild task to run the WiX compiler.
12 /// </summary>
13 public sealed class WixBuild : WixExeBaseTask
14 {
15 public string[] Cultures { get; set; }
16
17 public string[] DefineConstants { get; set; }
18
19 public ITaskItem[] Extensions { get; set; }
20
21 public string[] IncludeSearchPaths { get; set; }
22
23 public string InstallerPlatform { get; set; }
24
25 [Required]
26 public ITaskItem IntermediateDirectory { get; set; }
27
28 public ITaskItem[] LocalizationFiles { get; set; }
29
30 public ITaskItem[] LibraryFiles { get; set; }
31
32 [Required]
33 public ITaskItem OutputFile { get; set; }
34
35 public string OutputType { get; set; }
36
37 public ITaskItem PdbFile { get; set; }
38
39 public string PdbType { get; set; }
40
41 public bool Pedantic { get; set; }
42
43 [Required]
44 public ITaskItem[] SourceFiles { get; set; }
45
46 public ITaskItem[] BindPaths { get; set; }
47
48 public ITaskItem[] BindVariables { get; set; }
49
50 public bool BindFiles { get; set; }
51
52 public ITaskItem BindTrackingFile { get; set; }
53
54 public string CabinetCachePath { get; set; }
55
56 public int CabinetCreationThreadCount { get; set; }
57
58 public string DefaultCompressionLevel { get; set; }
59
60 protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
61 {
62 commandLineBuilder.AppendTextUnquoted("build");
63
64 commandLineBuilder.AppendSwitchIfNotNull("-platform ", this.InstallerPlatform);
65 commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
66 commandLineBuilder.AppendSwitchIfNotNull("-outputType ", this.OutputType);
67 commandLineBuilder.AppendSwitchIfNotNull("-pdb ", this.PdbFile);
68 commandLineBuilder.AppendSwitchIfNotNull("-pdbType ", this.PdbType);
69 commandLineBuilder.AppendArrayIfNotNull("-culture ", this.Cultures);
70 commandLineBuilder.AppendArrayIfNotNull("-d ", this.DefineConstants);
71 commandLineBuilder.AppendArrayIfNotNull("-I ", this.IncludeSearchPaths);
72 commandLineBuilder.AppendArrayIfNotNull("-ext ", this.Extensions);
73 commandLineBuilder.AppendSwitchIfNotNull("-cc ", this.CabinetCachePath);
74 commandLineBuilder.AppendSwitchIfNotNull("-intermediatefolder ", this.IntermediateDirectory);
75 commandLineBuilder.AppendSwitchIfNotNull("-trackingfile ", this.BindTrackingFile);
76 commandLineBuilder.AppendSwitchIfNotNull("-defaultcompressionlevel ", this.DefaultCompressionLevel);
77
78 base.BuildCommandLine(commandLineBuilder);
79
80 commandLineBuilder.AppendIfTrue("-bindFiles", this.BindFiles);
81 commandLineBuilder.AppendArrayIfNotNull("-bindPath ", this.CalculateBindPathStrings());
82 commandLineBuilder.AppendArrayIfNotNull("-bindVariable ", this.CalculateBindVariableStrings());
83 commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles);
84 commandLineBuilder.AppendArrayIfNotNull("-lib ", this.LibraryFiles);
85 commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
86 }
87
88 private IEnumerable<string> CalculateBindPathStrings()
89 {
90 if (null != this.BindPaths)
91 {
92 foreach (var item in this.BindPaths)
93 {
94 var path = item.GetMetadata("FullPath");
95
96 var bindName = item.GetMetadata("BindName");
97 if (!String.IsNullOrEmpty(bindName))
98 {
99 yield return String.Concat(bindName, "=", path);
100 }
101 else
102 {
103 yield return path;
104 }
105 }
106 }
107 }
108
109 private IEnumerable<string> CalculateBindVariableStrings()
110 {
111 if (null != this.BindVariables)
112 {
113 foreach (var item in this.BindVariables)
114 {
115 var value = item.ItemSpec;
116
117 var variableName = item.GetMetadata("Name");
118 if (!String.IsNullOrEmpty(variableName))
119 {
120 value = String.Concat(variableName, "=", value);
121 }
122
123 yield return value;
124 }
125 }
126 }
127 }
128 }