diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-05-28 21:21:24 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-05-28 23:10:12 +1000 |
| commit | 551f2a43de0465202e3a3aca24379481cc35733e (patch) | |
| tree | d2d404b1341cd3eac390c98b4e64baf3ab9f6d19 /src/WixToolset.BuildTasks/WixBuild.cs | |
| parent | ca37ac8d6a7a3bab2d5b33216e793760e7455bb9 (diff) | |
| download | wix-551f2a43de0465202e3a3aca24379481cc35733e.tar.gz wix-551f2a43de0465202e3a3aca24379481cc35733e.tar.bz2 wix-551f2a43de0465202e3a3aca24379481cc35733e.zip | |
Rename DoIt to WixBuild.
Diffstat (limited to 'src/WixToolset.BuildTasks/WixBuild.cs')
| -rw-r--r-- | src/WixToolset.BuildTasks/WixBuild.cs | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/WixBuild.cs b/src/WixToolset.BuildTasks/WixBuild.cs new file mode 100644 index 00000000..b8fb4136 --- /dev/null +++ b/src/WixToolset.BuildTasks/WixBuild.cs | |||
| @@ -0,0 +1,178 @@ | |||
| 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 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.Data; | ||
| 14 | using WixToolset.Extensibility.Services; | ||
| 15 | |||
| 16 | /// <summary> | ||
| 17 | /// An MSBuild task to run the WiX compiler. | ||
| 18 | /// </summary> | ||
| 19 | public sealed class WixBuild : ToolsetTask | ||
| 20 | { | ||
| 21 | public string[] Cultures { get; set; } | ||
| 22 | |||
| 23 | public string[] DefineConstants { get; set; } | ||
| 24 | |||
| 25 | public ITaskItem[] Extensions { get; set; } | ||
| 26 | |||
| 27 | public string ExtensionDirectory { get; set; } | ||
| 28 | |||
| 29 | public string[] IncludeSearchPaths { get; set; } | ||
| 30 | |||
| 31 | public string InstallerPlatform { get; set; } | ||
| 32 | |||
| 33 | [Required] | ||
| 34 | public ITaskItem IntermediateDirectory { get; set; } | ||
| 35 | |||
| 36 | public ITaskItem[] LocalizationFiles { get; set; } | ||
| 37 | |||
| 38 | public ITaskItem[] LibraryFiles { get; set; } | ||
| 39 | |||
| 40 | [Output] | ||
| 41 | [Required] | ||
| 42 | public ITaskItem OutputFile { get; set; } | ||
| 43 | |||
| 44 | public string OutputType { get; set; } | ||
| 45 | |||
| 46 | public ITaskItem PdbFile { get; set; } | ||
| 47 | |||
| 48 | public string PdbType { get; set; } | ||
| 49 | |||
| 50 | public bool Pedantic { get; set; } | ||
| 51 | |||
| 52 | [Required] | ||
| 53 | public ITaskItem[] SourceFiles { get; set; } | ||
| 54 | |||
| 55 | public string[] ReferencePaths { get; set; } | ||
| 56 | |||
| 57 | |||
| 58 | public ITaskItem[] BindInputPaths { get; set; } | ||
| 59 | |||
| 60 | public bool BindFiles { get; set; } | ||
| 61 | |||
| 62 | public ITaskItem BindContentsFile { get; set; } | ||
| 63 | |||
| 64 | public ITaskItem BindOutputsFile { get; set; } | ||
| 65 | |||
| 66 | public ITaskItem BindBuiltOutputsFile { get; set; } | ||
| 67 | |||
| 68 | public string CabinetCachePath { get; set; } | ||
| 69 | public int CabinetCreationThreadCount { get; set; } | ||
| 70 | public string DefaultCompressionLevel { get; set; } | ||
| 71 | |||
| 72 | [Output] | ||
| 73 | public ITaskItem UnreferencedSymbolsFile { get; set; } | ||
| 74 | |||
| 75 | public ITaskItem WixProjectFile { get; set; } | ||
| 76 | public string[] WixVariables { get; set; } | ||
| 77 | |||
| 78 | public bool SuppressValidation { get; set; } | ||
| 79 | public string[] SuppressIces { get; set; } | ||
| 80 | public string AdditionalCub { get; set; } | ||
| 81 | |||
| 82 | protected override string TaskShortName => "WIX"; | ||
| 83 | |||
| 84 | protected override void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString) | ||
| 85 | { | ||
| 86 | this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString); | ||
| 87 | |||
| 88 | var messaging = serviceProvider.GetService<IMessaging>(); | ||
| 89 | messaging.SetListener(listener); | ||
| 90 | |||
| 91 | var arguments = serviceProvider.GetService<ICommandLineArguments>(); | ||
| 92 | arguments.Populate(commandLineString); | ||
| 93 | |||
| 94 | var commandLine = serviceProvider.GetService<ICommandLine>(); | ||
| 95 | commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions); | ||
| 96 | commandLine.Arguments = arguments; | ||
| 97 | var command = commandLine.ParseStandardCommandLine(); | ||
| 98 | command?.Execute(); | ||
| 99 | } | ||
| 100 | |||
| 101 | protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
| 102 | { | ||
| 103 | commandLineBuilder.AppendTextUnquoted("build"); | ||
| 104 | |||
| 105 | commandLineBuilder.AppendSwitchIfNotNull("-platform ", this.InstallerPlatform); | ||
| 106 | commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile); | ||
| 107 | commandLineBuilder.AppendSwitchIfNotNull("-outputType ", this.OutputType); | ||
| 108 | commandLineBuilder.AppendSwitchIfNotNull("-pdb ", this.PdbFile); | ||
| 109 | commandLineBuilder.AppendSwitchIfNotNull("-pdbType ", this.PdbType); | ||
| 110 | commandLineBuilder.AppendArrayIfNotNull("-culture ", this.Cultures); | ||
| 111 | commandLineBuilder.AppendArrayIfNotNull("-d ", this.DefineConstants); | ||
| 112 | commandLineBuilder.AppendArrayIfNotNull("-I ", this.IncludeSearchPaths); | ||
| 113 | commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.ReferencePaths); | ||
| 114 | commandLineBuilder.AppendIfTrue("-sval", this.SuppressValidation); | ||
| 115 | commandLineBuilder.AppendArrayIfNotNull("-sice ", this.SuppressIces); | ||
| 116 | commandLineBuilder.AppendSwitchIfNotNull("-usf ", this.UnreferencedSymbolsFile); | ||
| 117 | commandLineBuilder.AppendSwitchIfNotNull("-cc ", this.CabinetCachePath); | ||
| 118 | commandLineBuilder.AppendSwitchIfNotNull("-intermediatefolder ", this.IntermediateDirectory); | ||
| 119 | commandLineBuilder.AppendSwitchIfNotNull("-contentsfile ", this.BindContentsFile); | ||
| 120 | commandLineBuilder.AppendSwitchIfNotNull("-outputsfile ", this.BindOutputsFile); | ||
| 121 | commandLineBuilder.AppendSwitchIfNotNull("-builtoutputsfile ", this.BindBuiltOutputsFile); | ||
| 122 | |||
| 123 | base.BuildCommandLine(commandLineBuilder); | ||
| 124 | |||
| 125 | commandLineBuilder.AppendIfTrue("-bindFiles", this.BindFiles); | ||
| 126 | commandLineBuilder.AppendArrayIfNotNull("-bindPath ", this.CalculateBindPathStrings()); | ||
| 127 | commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles); | ||
| 128 | commandLineBuilder.AppendArrayIfNotNull("-lib ", this.LibraryFiles); | ||
| 129 | commandLineBuilder.AppendTextIfNotWhitespace(this.AdditionalOptions); | ||
| 130 | commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " "); | ||
| 131 | } | ||
| 132 | |||
| 133 | private IExtensionManager CreateExtensionManagerWithStandardBackends(IWixToolsetServiceProvider serviceProvider, IMessaging messaging, string[] extensions) | ||
| 134 | { | ||
| 135 | var extensionManager = serviceProvider.GetService<IExtensionManager>(); | ||
| 136 | |||
| 137 | foreach (var type in new[] { typeof(WixToolset.Core.Burn.WixToolsetStandardBackend), typeof(WixToolset.Core.WindowsInstaller.WixToolsetStandardBackend) }) | ||
| 138 | { | ||
| 139 | extensionManager.Add(type.Assembly); | ||
| 140 | } | ||
| 141 | |||
| 142 | foreach (var extension in extensions) | ||
| 143 | { | ||
| 144 | try | ||
| 145 | { | ||
| 146 | extensionManager.Load(extension); | ||
| 147 | } | ||
| 148 | catch (WixException e) | ||
| 149 | { | ||
| 150 | messaging.Write(e.Error); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | return extensionManager; | ||
| 155 | } | ||
| 156 | |||
| 157 | private IEnumerable<string> CalculateBindPathStrings() | ||
| 158 | { | ||
| 159 | if (null != this.BindInputPaths) | ||
| 160 | { | ||
| 161 | foreach (var item in this.BindInputPaths) | ||
| 162 | { | ||
| 163 | var path = item.GetMetadata("FullPath"); | ||
| 164 | |||
| 165 | var bindName = item.GetMetadata("BindName"); | ||
| 166 | if (!String.IsNullOrEmpty(bindName)) | ||
| 167 | { | ||
| 168 | yield return String.Concat(bindName, "=", path); | ||
| 169 | } | ||
| 170 | else | ||
| 171 | { | ||
| 172 | yield return path; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
