//-------------------------------------------------------------------------------------------------
// <copyright file="CandleTask.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.
// </copyright>
//
// <summary>
// Build task to execute the compiler of the Windows Installer Xml toolset.
// </summary>
//-------------------------------------------------------------------------------------------------
namespace Microsoft.Tools.WindowsInstallerXml.Build.Tasks{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
/// <summary>
/// An MSBuild task to run the WiX compiler.
/// </summary>
public sealed class Candle : WixToolTask
{
private const string CandleToolName = "candle.exe";
private string[] defineConstants;
private ITaskItem[] extensions;
private bool suppressFilesVitalByDefault;
private string[] includeSearchPaths;
private bool onlyValidateDocuments;
private ITaskItem outputFile;
private bool pedantic;
private string installerPlatform;
private string preprocessToFile;
private bool preprocessToStdOut;
private bool showSourceTrace;
private ITaskItem[] sourceFiles;
private bool suppressSchemaValidation;
private string extensionDirectory;
private string[] referencePaths;
private bool fipsCompliant;
public string[] DefineConstants
{
get { return this.defineConstants; }
set { this.defineConstants = value; }
}
public ITaskItem[] Extensions
{
get { return this.extensions; }
set { this.extensions = value; }
}
public bool SuppressFilesVitalByDefault
{
get { return this.suppressFilesVitalByDefault; }
set { this.suppressFilesVitalByDefault = value; }
}
public string[] IncludeSearchPaths
{
get { return this.includeSearchPaths; }
set { this.includeSearchPaths = value; }
}
public string InstallerPlatform
{
get { return this.installerPlatform; }
set { this.installerPlatform = value; }
}
public bool OnlyValidateDocuments
{
get { return this.onlyValidateDocuments; }
set { this.onlyValidateDocuments = value; }
}
[Output]
[Required]
public ITaskItem OutputFile
{
get { return this.outputFile; }
set { this.outputFile = value; }
}
public bool Pedantic
{
get { return this.pedantic; }
set { this.pedantic = value; }
}
public string PreprocessToFile
{
get { return this.preprocessToFile; }
set { this.preprocessToFile = value; }
}
public bool PreprocessToStdOut
{
get { return this.preprocessToStdOut; }
set { this.preprocessToStdOut = value; }
}
public bool ShowSourceTrace
{
get { return this.showSourceTrace; }
set { this.showSourceTrace = value; }
}
[Required]
public ITaskItem[] SourceFiles
{
get { return this.sourceFiles; }
set { this.sourceFiles = value; }
}
public bool SuppressSchemaValidation
{
get { return this.suppressSchemaValidation; }
set { this.suppressSchemaValidation = value; }
}
public string ExtensionDirectory
{
get { return this.extensionDirectory; }
set { this.extensionDirectory = value; }
}
public string[] ReferencePaths
{
get { return this.referencePaths; }
set { this.referencePaths = value; }
}
public bool FipsCompliant
{
get { return this.fipsCompliant; }
set { this.fipsCompliant = value; }
}
/// <summary>
/// Get the name of the executable.
/// </summary>
/// <remarks>The ToolName is used with the ToolPath to get the location of candle.exe.</remarks>
/// <value>The name of the executable.</value>
protected override string ToolName
{
get { return CandleToolName; }
}
/// <summary>
/// Get the path to the executable.
/// </summary>
/// <remarks>GetFullPathToTool is only called when the ToolPath property is not set (see the ToolName remarks above).</remarks>
/// <returns>The full path to the executable or simply candle.exe if it's expected to be in the system path.</returns>
protected override string GenerateFullPathToTool()
{
// If there's not a ToolPath specified, it has to be in the system path.
if (String.IsNullOrEmpty(this.ToolPath))
{
return CandleToolName;
}
return Path.Combine(Path.GetFullPath(this.ToolPath), CandleToolName);
}
/// <summary>
/// Builds a command line from options in this task.
/// </summary>
protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
{
base.BuildCommandLine(commandLineBuilder);
commandLineBuilder.AppendArrayIfNotNull("-d", this.DefineConstants);
commandLineBuilder.AppendIfTrue("-p", this.PreprocessToStdOut);
commandLineBuilder.AppendSwitchIfNotNull("-p", this.PreprocessToFile);
commandLineBuilder.AppendIfTrue("-sfdvital", this.suppressFilesVitalByDefault);
commandLineBuilder.AppendArrayIfNotNull("-I", this.IncludeSearchPaths);
commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
commandLineBuilder.AppendIfTrue("-pedantic", this.Pedantic);
commandLineBuilder.AppendSwitchIfNotNull("-arch ", this.InstallerPlatform);
commandLineBuilder.AppendIfTrue("-ss", this.SuppressSchemaValidation);
commandLineBuilder.AppendIfTrue("-trace", this.ShowSourceTrace);
commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.referencePaths);
commandLineBuilder.AppendIfTrue("-zs", this.OnlyValidateDocuments);
commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
commandLineBuilder.AppendIfTrue("-fips", this.fipsCompliant);
}
}
}
|