Ejemplo n.º 1
0
        /// <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)
        {
            if (this.RunAsSeparateProcess)
            {
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            this.messageQueue      = new Queue <string>();
            this.messagesAvailable = new ManualResetEvent(false);
            this.toolExited        = new ManualResetEvent(false);

            Util.RunningInMsBuild = true;

            WixToolTaskLogger logger           = new WixToolTaskLogger(this.messageQueue, this.messagesAvailable);
            TextWriter        saveConsoleOut   = Console.Out;
            TextWriter        saveConsoleError = Console.Error;

            Console.SetOut(logger);
            Console.SetError(logger);

            string responseFile = null;

            try
            {
                string responseFileSwitch;
                responseFile = this.GetTemporaryResponseFile(responseFileCommands, out responseFileSwitch);
                if (!String.IsNullOrEmpty(responseFileSwitch))
                {
                    commandLineCommands = commandLineCommands + " " + responseFileSwitch;
                }

                string[] arguments = CommandLineResponseFile.ParseArgumentsToArray(commandLineCommands);

                Thread toolThread = new Thread(new ParameterizedThreadStart(this.ExecuteToolThread));
                toolThread.Start(new object[] { pathToTool, arguments });

                this.HandleToolMessages();

                if (this.exitCode == 0 && this.Log.HasLoggedErrors)
                {
                    this.exitCode = -1;
                }

                return(this.exitCode);
            }
            finally
            {
                if (responseFile != null)
                {
                    File.Delete(responseFile);
                }

                Console.SetOut(saveConsoleOut);
                Console.SetError(saveConsoleError);
            }
        }
Ejemplo n.º 2
0
        /// <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)
        {
            if (this.RunAsSeparateProcess)
            {
                return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
            }

            this.messageQueue = new Queue<string>();
            this.messagesAvailable = new ManualResetEvent(false);
            this.toolExited = new ManualResetEvent(false);

            Util.RunningInMsBuild = true;

            WixToolTaskLogger logger = new WixToolTaskLogger(this.messageQueue, this.messagesAvailable);
            TextWriter saveConsoleOut = Console.Out;
            TextWriter saveConsoleError = Console.Error;
            Console.SetOut(logger);
            Console.SetError(logger);

            string responseFile = null;
            try
            {
                string responseFileSwitch;
                responseFile = this.GetTemporaryResponseFile(responseFileCommands, out responseFileSwitch);
                if (!String.IsNullOrEmpty(responseFileSwitch))
                {
                    commandLineCommands = commandLineCommands + " " + responseFileSwitch;
                }

                string[] arguments = CommandLineResponseFile.ParseArgumentsToArray(commandLineCommands);

                Thread toolThread = new Thread(new ParameterizedThreadStart(this.ExecuteToolThread));
                toolThread.Start(new object[] { pathToTool, arguments });

                this.HandleToolMessages();

                if (this.exitCode == 0 && this.Log.HasLoggedErrors)
                {
                    this.exitCode = -1;
                }

                return this.exitCode;
            }
            finally
            {
                if (responseFile != null)
                {
                    File.Delete(responseFile);
                }

                Console.SetOut(saveConsoleOut);
                Console.SetError(saveConsoleError);
            }
        }