From 82a26a321bae36e38743f50f38887387a392ce24 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 1 Jun 2020 21:58:44 +1000 Subject: Add ability for net461 tasks to run the tool out of proc. --- src/WixToolset.BuildTasks/HeatTask.cs | 9 ++-- src/WixToolset.BuildTasks/ToolsetTask.cs | 76 +++++++++++++++++++++++++++----- src/WixToolset.BuildTasks/WixBuild.cs | 10 ++--- 3 files changed, 73 insertions(+), 22 deletions(-) (limited to 'src/WixToolset.BuildTasks') diff --git a/src/WixToolset.BuildTasks/HeatTask.cs b/src/WixToolset.BuildTasks/HeatTask.cs index 586f02f7..5feed26d 100644 --- a/src/WixToolset.BuildTasks/HeatTask.cs +++ b/src/WixToolset.BuildTasks/HeatTask.cs @@ -59,7 +59,8 @@ namespace WixToolset.BuildTasks set { this.transforms = value; } } - protected override string TaskShortName => "HEAT"; + protected sealed override string TaskShortName => "HEAT"; + protected sealed override string ToolName => "heat.exe"; /// /// Gets the name of the heat operation performed by the task. @@ -71,10 +72,8 @@ namespace WixToolset.BuildTasks get; } - protected override void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString) + protected sealed override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString) { - this.Log.LogMessage(MessageImportance.Normal, "heat.exe " + commandLineString); - var messaging = serviceProvider.GetService(); messaging.SetListener(listener); @@ -83,7 +82,7 @@ namespace WixToolset.BuildTasks var commandLine = HeatCommandLineFactory.CreateCommandLine(serviceProvider, true); var command = commandLine.ParseStandardCommandLine(arguments); - command?.Execute(); + return command?.Execute() ?? -1; } /// diff --git a/src/WixToolset.BuildTasks/ToolsetTask.cs b/src/WixToolset.BuildTasks/ToolsetTask.cs index 713a938b..fe6812fc 100644 --- a/src/WixToolset.BuildTasks/ToolsetTask.cs +++ b/src/WixToolset.BuildTasks/ToolsetTask.cs @@ -3,14 +3,16 @@ namespace WixToolset.BuildTasks { using System; + using System.IO; using System.Runtime.InteropServices; + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using WixToolset.Core; using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Services; - public abstract class ToolsetTask : Task + public abstract class ToolsetTask : ToolTask { /// /// Gets or sets additional options that are appended the the tool command-line. @@ -26,6 +28,12 @@ namespace WixToolset.BuildTasks /// public bool NoLogo { get; set; } + /// + /// Gets or sets a flag indicating whether the task + /// should be run as separate process or in-proc. + /// + public bool RunAsSeparateProcess { get; set; } + /// /// Gets or sets whether all warnings should be suppressed. /// @@ -51,19 +59,27 @@ namespace WixToolset.BuildTasks /// public bool VerboseOutput { get; set; } - public override bool Execute() + protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { - var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); + if (this.RunAsSeparateProcess) + { + return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands); + } + + return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}"); + } + private int ExecuteInProc(string commandLineString) + { + this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}"); + + var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode); + int exitCode = -1; try { - var commandLineBuilder = new WixCommandLineBuilder(); - this.BuildCommandLine(commandLineBuilder); - - var commandLineString = commandLineBuilder.ToString(); - this.ExecuteCore(serviceProvider, listener, commandLineString); + exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString); } catch (WixException e) { @@ -79,7 +95,47 @@ namespace WixToolset.BuildTasks } } - return !this.Log.HasLoggedErrors; + if (exitCode == 0 && this.Log.HasLoggedErrors) + { + exitCode = -1; + } + return exitCode; + } + + /// + /// Get the path to the executable. + /// + /// + /// ToolTask only calls GenerateFullPathToTool when the ToolPath property is not set. + /// WiX never sets the ToolPath property, but the user can through $(WixToolDir). + /// If we return only a file name, ToolTask will search the system paths for it. + /// + protected sealed override string GenerateFullPathToTool() + { + var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; + if (this.RunAsSeparateProcess) + { + return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe); + } + + // We need to return a path that exists, so if we're not actually going to run the tool then just return this dll path. + return thisDllPath; + } + + protected sealed override string GenerateResponseFileCommands() + { + var commandLineBuilder = new WixCommandLineBuilder(); + this.BuildCommandLine(commandLineBuilder); + return commandLineBuilder.ToString(); + } + + protected sealed override void LogToolCommand(string message) + { + // Only log this if we're actually going to do it. + if (this.RunAsSeparateProcess) + { + base.LogToolCommand(message); + } } /// @@ -98,7 +154,7 @@ namespace WixToolset.BuildTasks commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); } - protected abstract void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString); + protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString); protected abstract string TaskShortName { get; } } diff --git a/src/WixToolset.BuildTasks/WixBuild.cs b/src/WixToolset.BuildTasks/WixBuild.cs index b8fb4136..c15bc2f7 100644 --- a/src/WixToolset.BuildTasks/WixBuild.cs +++ b/src/WixToolset.BuildTasks/WixBuild.cs @@ -4,10 +4,7 @@ namespace WixToolset.BuildTasks { using System; using System.Collections.Generic; - using System.Runtime.InteropServices; using Microsoft.Build.Framework; - using Microsoft.Build.Utilities; - using WixToolset.Core; using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; @@ -80,11 +77,10 @@ namespace WixToolset.BuildTasks public string AdditionalCub { get; set; } protected override string TaskShortName => "WIX"; + protected override string ToolName => "wix.exe"; - protected override void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString) + protected override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString) { - this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString); - var messaging = serviceProvider.GetService(); messaging.SetListener(listener); @@ -95,7 +91,7 @@ namespace WixToolset.BuildTasks commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions); commandLine.Arguments = arguments; var command = commandLine.ParseStandardCommandLine(); - command?.Execute(); + return command?.Execute() ?? -1; } protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) -- cgit v1.2.3-55-g6feb