// 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.Runtime.InteropServices;
using Microsoft.Build.Utilities;
using WixToolset.Core;
using WixToolset.Data;
using WixToolset.Extensibility;
using WixToolset.Extensibility.Services;
public abstract class ToolsetTask : Task
{
///
/// Gets or sets additional options that are appended the the tool command-line.
///
///
/// This allows the task to support extended options in the tool which are not
/// explicitly implemented as properties on the task.
///
public string AdditionalOptions { get; set; }
///
/// Gets or sets whether to display the logo.
///
public bool NoLogo { get; set; }
///
/// Gets or sets whether all warnings should be suppressed.
///
public bool SuppressAllWarnings { get; set; }
///
/// Gets or sets a list of specific warnings to be suppressed.
///
public string[] SuppressSpecificWarnings { get; set; }
///
/// Gets or sets whether all warnings should be treated as errors.
///
public bool TreatWarningsAsErrors { get; set; }
///
/// Gets or sets a list of specific warnings to treat as errors.
///
public string[] TreatSpecificWarningsAsErrors { get; set; }
///
/// Gets or sets whether to display verbose output.
///
public bool VerboseOutput { get; set; }
public override bool Execute()
{
var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode);
try
{
var commandLineBuilder = new WixCommandLineBuilder();
this.BuildCommandLine(commandLineBuilder);
var commandLineString = commandLineBuilder.ToString();
this.ExecuteCore(serviceProvider, listener, commandLineString);
}
catch (WixException e)
{
listener.Write(e.Error);
}
catch (Exception e)
{
this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null);
if (e is NullReferenceException || e is SEHException)
{
throw;
}
}
return !this.Log.HasLoggedErrors;
}
///
/// Builds a command line from options in this and derivative tasks.
///
///
/// Derivative classes should call BuildCommandLine() on the base class to ensure that common command line options are added to the command.
///
protected virtual void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
{
commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo);
commandLineBuilder.AppendArrayIfNotNull("-sw ", this.SuppressSpecificWarnings);
commandLineBuilder.AppendIfTrue("-sw", this.SuppressAllWarnings);
commandLineBuilder.AppendIfTrue("-v", this.VerboseOutput);
commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors);
commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors);
}
protected abstract void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString);
protected abstract string TaskShortName { get; }
}
}