diff options
Diffstat (limited to 'src/WixToolset.BuildTasks/DoIt.cs')
| -rw-r--r-- | src/WixToolset.BuildTasks/DoIt.cs | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/DoIt.cs b/src/WixToolset.BuildTasks/DoIt.cs new file mode 100644 index 00000000..7688342c --- /dev/null +++ b/src/WixToolset.BuildTasks/DoIt.cs | |||
| @@ -0,0 +1,233 @@ | |||
| 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 Microsoft.Build.Framework; | ||
| 6 | using Microsoft.Build.Utilities; | ||
| 7 | using WixToolset.Core; | ||
| 8 | using WixToolset.Data; | ||
| 9 | |||
| 10 | /// <summary> | ||
| 11 | /// An MSBuild task to run the WiX compiler. | ||
| 12 | /// </summary> | ||
| 13 | public sealed class DoIt : Task | ||
| 14 | { | ||
| 15 | public DoIt() | ||
| 16 | { | ||
| 17 | Messaging.Instance.InitializeAppName("WIX", "wix.exe"); | ||
| 18 | |||
| 19 | Messaging.Instance.Display += this.DisplayMessage; | ||
| 20 | } | ||
| 21 | |||
| 22 | public string AdditionalOptions { get; set; } | ||
| 23 | |||
| 24 | public string Cultures { get; set; } | ||
| 25 | |||
| 26 | public string[] DefineConstants { get; set; } | ||
| 27 | |||
| 28 | public ITaskItem[] Extensions { get; set; } | ||
| 29 | |||
| 30 | public string ExtensionDirectory { get; set; } | ||
| 31 | |||
| 32 | public string[] IncludeSearchPaths { get; set; } | ||
| 33 | |||
| 34 | public string InstallerPlatform { get; set; } | ||
| 35 | |||
| 36 | [Required] | ||
| 37 | public ITaskItem IntermediateDirectory { get; set; } | ||
| 38 | |||
| 39 | public ITaskItem[] LocalizationFiles { get; set; } | ||
| 40 | |||
| 41 | public bool NoLogo { get; set; } | ||
| 42 | |||
| 43 | public ITaskItem[] ObjectFiles { get; set; } | ||
| 44 | |||
| 45 | [Output] | ||
| 46 | [Required] | ||
| 47 | public ITaskItem OutputFile { 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 | public bool BindFiles { get; set; } | ||
| 87 | public ITaskItem BindContentsFile{ get; set; } | ||
| 88 | public ITaskItem BindOutputsFile { get; set; } | ||
| 89 | public ITaskItem BindBuiltOutputsFile { get; set; } | ||
| 90 | |||
| 91 | public string CabinetCachePath { get; set; } | ||
| 92 | public int CabinetCreationThreadCount { get; set; } | ||
| 93 | public string DefaultCompressionLevel { get; set; } | ||
| 94 | |||
| 95 | [Output] | ||
| 96 | public ITaskItem UnreferencedSymbolsFile { get; set; } | ||
| 97 | |||
| 98 | public ITaskItem WixProjectFile { get; set; } | ||
| 99 | public string[] WixVariables { get; set; } | ||
| 100 | |||
| 101 | public bool SuppressValidation { get; set; } | ||
| 102 | public string[] SuppressIces { get; set; } | ||
| 103 | public string AdditionalCub { get; set; } | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | public override bool Execute() | ||
| 108 | { | ||
| 109 | try | ||
| 110 | { | ||
| 111 | this.ExecuteCore(); | ||
| 112 | } | ||
| 113 | catch (BuildException e) | ||
| 114 | { | ||
| 115 | this.Log.LogErrorFromException(e); | ||
| 116 | } | ||
| 117 | catch (WixException e) | ||
| 118 | { | ||
| 119 | this.Log.LogErrorFromException(e); | ||
| 120 | } | ||
| 121 | |||
| 122 | return !this.Log.HasLoggedErrors; | ||
| 123 | } | ||
| 124 | |||
| 125 | private void ExecuteCore() | ||
| 126 | { | ||
| 127 | var commandLineBuilder = new WixCommandLineBuilder(); | ||
| 128 | |||
| 129 | commandLineBuilder.AppendTextUnquoted("build"); | ||
| 130 | |||
| 131 | commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile); | ||
| 132 | commandLineBuilder.AppendSwitchIfNotNull("-cultures ", this.Cultures); | ||
| 133 | commandLineBuilder.AppendArrayIfNotNull("-d ", this.DefineConstants); | ||
| 134 | commandLineBuilder.AppendArrayIfNotNull("-I ", this.IncludeSearchPaths); | ||
| 135 | commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.ReferencePaths); | ||
| 136 | commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo); | ||
| 137 | commandLineBuilder.AppendIfTrue("-sval", this.SuppressValidation); | ||
| 138 | commandLineBuilder.AppendArrayIfNotNull("-sice ", this.SuppressIces); | ||
| 139 | commandLineBuilder.AppendSwitchIfNotNull("-usf ", this.UnreferencedSymbolsFile); | ||
| 140 | commandLineBuilder.AppendSwitchIfNotNull("-cc ", this.CabinetCachePath); | ||
| 141 | commandLineBuilder.AppendSwitchIfNotNull("-contentsfile ", this.BindContentsFile); | ||
| 142 | commandLineBuilder.AppendSwitchIfNotNull("-outputsfile ", this.BindOutputsFile); | ||
| 143 | commandLineBuilder.AppendSwitchIfNotNull("-builtoutputsfile ", this.BindBuiltOutputsFile); | ||
| 144 | commandLineBuilder.AppendSwitchIfNotNull("-wixprojectfile ", this.WixProjectFile); | ||
| 145 | commandLineBuilder.AppendTextIfNotWhitespace(this.AdditionalOptions); | ||
| 146 | |||
| 147 | commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles); | ||
| 148 | commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " "); | ||
| 149 | |||
| 150 | var commandLineString = commandLineBuilder.ToString(); | ||
| 151 | |||
| 152 | this.Log.LogMessage(MessageImportance.Normal, commandLineString); | ||
| 153 | |||
| 154 | var command = CommandLine.ParseStandardCommandLine(commandLineString); | ||
| 155 | command?.Execute(); | ||
| 156 | } | ||
| 157 | |||
| 158 | private void DisplayMessage(object sender, DisplayEventArgs e) | ||
| 159 | { | ||
| 160 | this.Log.LogMessageFromText(e.Message, MessageImportance.Normal); | ||
| 161 | } | ||
| 162 | |||
| 163 | ///// <summary> | ||
| 164 | ///// Builds a command line from options in this task. | ||
| 165 | ///// </summary> | ||
| 166 | //protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
| 167 | //{ | ||
| 168 | // base.BuildCommandLine(commandLineBuilder); | ||
| 169 | |||
| 170 | // commandLineBuilder.AppendIfTrue("-p", this.PreprocessToStdOut); | ||
| 171 | // commandLineBuilder.AppendSwitchIfNotNull("-p", this.PreprocessToFile); | ||
| 172 | // commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile); | ||
| 173 | // commandLineBuilder.AppendArrayIfNotNull("-d", this.DefineConstants); | ||
| 174 | // commandLineBuilder.AppendArrayIfNotNull("-I", this.IncludeSearchPaths); | ||
| 175 | // commandLineBuilder.AppendIfTrue("-pedantic", this.Pedantic); | ||
| 176 | // commandLineBuilder.AppendSwitchIfNotNull("-arch ", this.InstallerPlatform); | ||
| 177 | // commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.referencePaths); | ||
| 178 | // commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions); | ||
| 179 | |||
| 180 | // // Support per-source-file output by looking at the SourceFiles items to | ||
| 181 | // // see if there is any "CandleOutput" metadata. If there is, we do our own | ||
| 182 | // // appending, otherwise we fall back to the built-in "append file names" code. | ||
| 183 | // // Note also that the wix.targets "Compile" target does *not* automagically | ||
| 184 | // // fix the "@(CompileObjOutput)" list to include these new output names. | ||
| 185 | // // If you really want to use this, you're going to have to clone the target | ||
| 186 | // // in your own .targets file and create the output list yourself. | ||
| 187 | // bool usePerSourceOutput = false; | ||
| 188 | // if (this.SourceFiles != null) | ||
| 189 | // { | ||
| 190 | // foreach (ITaskItem item in this.SourceFiles) | ||
| 191 | // { | ||
| 192 | // if (!String.IsNullOrEmpty(item.GetMetadata("CandleOutput"))) | ||
| 193 | // { | ||
| 194 | // usePerSourceOutput = true; | ||
| 195 | // break; | ||
| 196 | // } | ||
| 197 | // } | ||
| 198 | // } | ||
| 199 | |||
| 200 | // if (usePerSourceOutput) | ||
| 201 | // { | ||
| 202 | // string[] newSourceNames = new string[this.SourceFiles.Length]; | ||
| 203 | // for (int iSource = 0; iSource < this.SourceFiles.Length; ++iSource) | ||
| 204 | // { | ||
| 205 | // ITaskItem item = this.SourceFiles[iSource]; | ||
| 206 | // if (null == item) | ||
| 207 | // { | ||
| 208 | // newSourceNames[iSource] = null; | ||
| 209 | // } | ||
| 210 | // else | ||
| 211 | // { | ||
| 212 | // string output = item.GetMetadata("CandleOutput"); | ||
| 213 | |||
| 214 | // if (!String.IsNullOrEmpty(output)) | ||
| 215 | // { | ||
| 216 | // newSourceNames[iSource] = String.Concat(item.ItemSpec, ";", output); | ||
| 217 | // } | ||
| 218 | // else | ||
| 219 | // { | ||
| 220 | // newSourceNames[iSource] = item.ItemSpec; | ||
| 221 | // } | ||
| 222 | // } | ||
| 223 | // } | ||
| 224 | |||
| 225 | // commandLineBuilder.AppendFileNamesIfNotNull(newSourceNames, " "); | ||
| 226 | // } | ||
| 227 | // else | ||
| 228 | // { | ||
| 229 | // commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " "); | ||
| 230 | // } | ||
| 231 | //} | ||
| 232 | } | ||
| 233 | } | ||
