aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/DoIt.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.BuildTasks/DoIt.cs')
-rw-r--r--src/WixToolset.BuildTasks/DoIt.cs342
1 files changed, 0 insertions, 342 deletions
diff --git a/src/WixToolset.BuildTasks/DoIt.cs b/src/WixToolset.BuildTasks/DoIt.cs
deleted file mode 100644
index 02b33522..00000000
--- a/src/WixToolset.BuildTasks/DoIt.cs
+++ /dev/null
@@ -1,342 +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.BuildTasks
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Runtime.InteropServices;
8 using Microsoft.Build.Framework;
9 using Microsoft.Build.Utilities;
10 using WixToolset.Core;
11 using WixToolset.Data;
12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
14
15 /// <summary>
16 /// An MSBuild task to run the WiX compiler.
17 /// </summary>
18 public sealed class DoIt : Task
19 {
20 public string AdditionalOptions { get; set; }
21
22 public string[] Cultures { get; set; }
23
24 public string[] DefineConstants { get; set; }
25
26 public ITaskItem[] Extensions { get; set; }
27
28 public string ExtensionDirectory { get; set; }
29
30 public string[] IncludeSearchPaths { get; set; }
31
32 public string InstallerPlatform { get; set; }
33
34 [Required]
35 public ITaskItem IntermediateDirectory { get; set; }
36
37 public ITaskItem[] LocalizationFiles { get; set; }
38
39 public bool NoLogo { get; set; }
40
41 public ITaskItem[] LibraryFiles { get; set; }
42
43 [Output]
44 [Required]
45 public ITaskItem OutputFile { get; set; }
46
47 public string OutputType { get; set; }
48
49 public string PdbOutputFile { get; set; }
50
51 public bool Pedantic { get; set; }
52
53 [Required]
54 public ITaskItem[] SourceFiles { get; set; }
55
56 public string[] ReferencePaths { get; set; }
57
58
59 /// <summary>
60 /// Gets or sets whether all warnings should be suppressed.
61 /// </summary>
62 public bool SuppressAllWarnings { get; set; }
63
64 /// <summary>
65 /// Gets or sets a list of specific warnings to be suppressed.
66 /// </summary>
67 public string[] SuppressSpecificWarnings { get; set; }
68
69 /// <summary>
70 /// Gets or sets whether all warnings should be treated as errors.
71 /// </summary>
72 public bool TreatWarningsAsErrors { get; set; }
73
74 /// <summary>
75 /// Gets or sets a list of specific warnings to treat as errors.
76 /// </summary>
77 public string[] TreatSpecificWarningsAsErrors { get; set; }
78
79 /// <summary>
80 /// Gets or sets whether to display verbose output.
81 /// </summary>
82 public bool VerboseOutput { get; set; }
83
84
85 public ITaskItem[] BindInputPaths { get; set; }
86
87 public bool BindFiles { get; set; }
88
89 public ITaskItem BindContentsFile { get; set; }
90
91 public ITaskItem BindOutputsFile { get; set; }
92
93 public ITaskItem BindBuiltOutputsFile { get; set; }
94
95 public string CabinetCachePath { get; set; }
96 public int CabinetCreationThreadCount { get; set; }
97 public string DefaultCompressionLevel { get; set; }
98
99 [Output]
100 public ITaskItem UnreferencedSymbolsFile { get; set; }
101
102 public ITaskItem WixProjectFile { get; set; }
103 public string[] WixVariables { get; set; }
104
105 public bool SuppressValidation { get; set; }
106 public string[] SuppressIces { get; set; }
107 public string AdditionalCub { get; set; }
108
109 public override bool Execute()
110 {
111 try
112 {
113 this.ExecuteCore();
114 }
115 catch (Exception e)
116 {
117 this.Log.LogErrorFromException(e);
118
119 if (e is NullReferenceException || e is SEHException)
120 {
121 throw;
122 }
123 }
124
125 return !this.Log.HasLoggedErrors;
126 }
127
128 private void ExecuteCore()
129 {
130 var listener = new MsbuildMessageListener(this.Log, "WIX", this.BuildEngine.ProjectFileOfTaskNode);
131
132 var commandLineBuilder = new WixCommandLineBuilder();
133
134 commandLineBuilder.AppendTextUnquoted("build");
135
136 commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
137 commandLineBuilder.AppendSwitchIfNotNull("-outputType ", this.OutputType);
138 commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo);
139 commandLineBuilder.AppendArrayIfNotNull("-culture ", this.Cultures);
140 commandLineBuilder.AppendArrayIfNotNull("-d ", this.DefineConstants);
141 commandLineBuilder.AppendArrayIfNotNull("-I ", this.IncludeSearchPaths);
142 commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.ReferencePaths);
143 commandLineBuilder.AppendIfTrue("-sval", this.SuppressValidation);
144 commandLineBuilder.AppendArrayIfNotNull("-sice ", this.SuppressIces);
145 commandLineBuilder.AppendSwitchIfNotNull("-usf ", this.UnreferencedSymbolsFile);
146 commandLineBuilder.AppendSwitchIfNotNull("-cc ", this.CabinetCachePath);
147 commandLineBuilder.AppendSwitchIfNotNull("-intermediatefolder ", this.IntermediateDirectory);
148 commandLineBuilder.AppendSwitchIfNotNull("-contentsfile ", this.BindContentsFile);
149 commandLineBuilder.AppendSwitchIfNotNull("-outputsfile ", this.BindOutputsFile);
150 commandLineBuilder.AppendSwitchIfNotNull("-builtoutputsfile ", this.BindBuiltOutputsFile);
151
152 commandLineBuilder.AppendIfTrue("-bindFiles", this.BindFiles);
153 commandLineBuilder.AppendArrayIfNotNull("-bindPath ", this.CalculateBindPathStrings());
154 commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles);
155 commandLineBuilder.AppendArrayIfNotNull("-lib ", this.LibraryFiles);
156 commandLineBuilder.AppendTextIfNotWhitespace(this.AdditionalOptions);
157 commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
158
159 var commandLineString = commandLineBuilder.ToString();
160
161 this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString);
162
163 var serviceProvider = new WixToolsetServiceProvider();
164
165 var messaging = serviceProvider.GetService<IMessaging>();
166 messaging.SetListener(listener);
167
168 var arguments = serviceProvider.GetService<ICommandLineArguments>();
169 arguments.Populate(commandLineString);
170
171 var context = serviceProvider.GetService<ICommandLineContext>();
172 context.Messaging = messaging;
173 context.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, arguments.Extensions);
174 context.Arguments = arguments;
175
176 var commandLine = serviceProvider.GetService<ICommandLine>();
177 var command = commandLine.ParseStandardCommandLine(context);
178 command?.Execute();
179 }
180
181 private IExtensionManager CreateExtensionManagerWithStandardBackends(IServiceProvider serviceProvider, string[] extensions)
182 {
183 var extensionManager = serviceProvider.GetService<IExtensionManager>();
184
185 foreach (var type in new[] { typeof(WixToolset.Core.Burn.WixToolsetStandardBackend), typeof(WixToolset.Core.WindowsInstaller.WixToolsetStandardBackend) })
186 {
187 extensionManager.Add(type.Assembly);
188 }
189
190 foreach (var extension in extensions)
191 {
192 extensionManager.Load(extension);
193 }
194
195 return extensionManager;
196 }
197
198 private void DisplayMessage(object sender, DisplayEventArgs e)
199 {
200 this.Log.LogMessageFromText(e.Message, MessageImportance.Normal);
201 }
202
203 private IEnumerable<string> CalculateBindPathStrings()
204 {
205 if (null != this.BindInputPaths)
206 {
207 foreach (var item in this.BindInputPaths)
208 {
209 var path = item.GetMetadata("FullPath");
210
211 var bindName = item.GetMetadata("BindName");
212 if (!String.IsNullOrEmpty(bindName))
213 {
214 yield return String.Concat(bindName, "=", path);
215 }
216 else
217 {
218 yield return path;
219 }
220 }
221 }
222 }
223
224 ///// <summary>
225 ///// Builds a command line from options in this task.
226 ///// </summary>
227 //protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
228 //{
229 // base.BuildCommandLine(commandLineBuilder);
230
231 // commandLineBuilder.AppendIfTrue("-p", this.PreprocessToStdOut);
232 // commandLineBuilder.AppendSwitchIfNotNull("-p", this.PreprocessToFile);
233 // commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
234 // commandLineBuilder.AppendArrayIfNotNull("-d", this.DefineConstants);
235 // commandLineBuilder.AppendArrayIfNotNull("-I", this.IncludeSearchPaths);
236 // commandLineBuilder.AppendIfTrue("-pedantic", this.Pedantic);
237 // commandLineBuilder.AppendSwitchIfNotNull("-arch ", this.InstallerPlatform);
238 // commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.referencePaths);
239 // commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
240
241 // // Support per-source-file output by looking at the SourceFiles items to
242 // // see if there is any "CandleOutput" metadata. If there is, we do our own
243 // // appending, otherwise we fall back to the built-in "append file names" code.
244 // // Note also that the wix.targets "Compile" target does *not* automagically
245 // // fix the "@(CompileObjOutput)" list to include these new output names.
246 // // If you really want to use this, you're going to have to clone the target
247 // // in your own .targets file and create the output list yourself.
248 // bool usePerSourceOutput = false;
249 // if (this.SourceFiles != null)
250 // {
251 // foreach (ITaskItem item in this.SourceFiles)
252 // {
253 // if (!String.IsNullOrEmpty(item.GetMetadata("CandleOutput")))
254 // {
255 // usePerSourceOutput = true;
256 // break;
257 // }
258 // }
259 // }
260
261 // if (usePerSourceOutput)
262 // {
263 // string[] newSourceNames = new string[this.SourceFiles.Length];
264 // for (int iSource = 0; iSource < this.SourceFiles.Length; ++iSource)
265 // {
266 // ITaskItem item = this.SourceFiles[iSource];
267 // if (null == item)
268 // {
269 // newSourceNames[iSource] = null;
270 // }
271 // else
272 // {
273 // string output = item.GetMetadata("CandleOutput");
274
275 // if (!String.IsNullOrEmpty(output))
276 // {
277 // newSourceNames[iSource] = String.Concat(item.ItemSpec, ";", output);
278 // }
279 // else
280 // {
281 // newSourceNames[iSource] = item.ItemSpec;
282 // }
283 // }
284 // }
285
286 // commandLineBuilder.AppendFileNamesIfNotNull(newSourceNames, " ");
287 // }
288 // else
289 // {
290 // commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
291 // }
292 //}
293
294 private class MsbuildMessageListener : IMessageListener
295 {
296 public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName)
297 {
298 this.Logger = logger;
299 this.ShortAppName = shortName;
300 this.LongAppName = longName;
301 }
302
303 public string ShortAppName { get; }
304
305 public string LongAppName { get; }
306
307 private TaskLoggingHelper Logger { get; }
308
309 public void Write(Message message)
310 {
311 switch (message.Level)
312 {
313 case MessageLevel.Error:
314 this.Logger.LogError(null, this.ShortAppName + message.Id.ToString(), null, message.SourceLineNumbers?.FileName ?? this.LongAppName, message.SourceLineNumbers?.LineNumber ?? 0, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
315 break;
316
317 case MessageLevel.Warning:
318 this.Logger.LogWarning(null, this.ShortAppName + message.Id.ToString(), null, message.SourceLineNumbers?.FileName ?? this.LongAppName, message.SourceLineNumbers?.LineNumber ?? 0, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
319 break;
320
321 default:
322 // TODO: Revisit this because something is going horribly awry. The commented out LogMessage call is crashing saying that the "message" parameter is null. When you look at the call stack, the code
323 // is in the wrong LogMessage override and the "null" subcategory was passed in as the message. Not clear why it is picking the wrong overload.
324 //if (message.Id > 0)
325 //{
326 // this.Logger.LogMessage(null, code, null, message.SourceLineNumber?.FileName, message.SourceLineNumber?.LineNumber ?? 0, 0, 0, 0, MessageImportance.Normal, message.Format, message.FormatData);
327 //}
328 //else
329 //{
330 this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs);
331 //}
332 break;
333 }
334 }
335
336 public void Write(string message)
337 {
338 this.Logger.LogMessage(MessageImportance.Low, message);
339 }
340 }
341 }
342}