aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/Insignia.cs
blob: ba30963a4e360b7878b780b472ae21beadab6d2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// 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.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 transform generator.
    /// </summary>
    public sealed class Insignia : WixToolTask
    {
        private const string InsigniaToolName = "insignia.exe";

        /// <summary>
        /// Gets or sets the path to the database to inscribe.
        /// </summary>
        public ITaskItem DatabaseFile { get; set; }

        /// <summary>
        /// Gets or sets the path to the bundle to inscribe.
        /// </summary>
        public ITaskItem BundleFile { get; set; }

        /// <summary>
        /// Gets or sets the path to the original bundle that contains the attached container.
        /// </summary>
        public ITaskItem OriginalBundleFile { get; set; }

        /// <summary>
        /// Gets or sets the path to output the inscribed result.
        /// </summary>
        [Required]
        public ITaskItem OutputFile { get; set; }

        /// <summary>
        /// Gets or sets the output. Only set if insignia does work.
        /// </summary>
        [Output]
        public ITaskItem Output { get; set; }

        /// <summary>
        /// Get the name of the executable.
        /// </summary>
        /// <remarks>The ToolName is used with the ToolPath to get the location of Insignia.exe.</remarks>
        /// <value>The name of the executable.</value>
        protected override string ToolName
        {
            get { return InsigniaToolName; }
        }

        /// <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 Insignia.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 InsigniaToolName;
            }

            return Path.Combine(Path.GetFullPath(this.ToolPath), InsigniaToolName);
        }

        /// <summary>
        /// Builds a command line from options in this task.
        /// </summary>
        protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
        {
            base.BuildCommandLine(commandLineBuilder);

            commandLineBuilder.AppendSwitchIfNotNull("-im ", this.DatabaseFile);
            if (null != this.OriginalBundleFile)
            {
                commandLineBuilder.AppendSwitchIfNotNull("-ab ", this.BundleFile);
                commandLineBuilder.AppendFileNameIfNotNull(this.OriginalBundleFile);
            }
            else
            {
                commandLineBuilder.AppendSwitchIfNotNull("-ib ", this.BundleFile);
            }

            commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
            commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
        }

        /// <summary>
        /// Executes a tool in-process by loading the tool assembly and invoking its entrypoint.
        /// </summary>
        /// <param name="pathToTool">Path to the tool to be executed; must be a managed executable.</param>
        /// <param name="responseFileCommands">Commands to be written to a response file.</param>
        /// <param name="commandLineCommands">Commands to be passed directly on the command-line.</param>
        /// <returns>The tool exit code.</returns>
        protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            int returnCode = base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
            if (0 == returnCode) // successfully did work.
            {
                this.Output = this.OutputFile;
            }
            else if (-1 == returnCode) // no work done.
            {
                returnCode = 0;
            }

            return returnCode;
        }
    }
}