aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/ToolsetTask.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.BuildTasks/ToolsetTask.cs')
-rw-r--r--src/WixToolset.BuildTasks/ToolsetTask.cs76
1 files changed, 66 insertions, 10 deletions
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 @@
3namespace WixToolset.BuildTasks 3namespace WixToolset.BuildTasks
4{ 4{
5 using System; 5 using System;
6 using System.IO;
6 using System.Runtime.InteropServices; 7 using System.Runtime.InteropServices;
8 using Microsoft.Build.Framework;
7 using Microsoft.Build.Utilities; 9 using Microsoft.Build.Utilities;
8 using WixToolset.Core; 10 using WixToolset.Core;
9 using WixToolset.Data; 11 using WixToolset.Data;
10 using WixToolset.Extensibility; 12 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services; 13 using WixToolset.Extensibility.Services;
12 14
13 public abstract class ToolsetTask : Task 15 public abstract class ToolsetTask : ToolTask
14 { 16 {
15 /// <summary> 17 /// <summary>
16 /// Gets or sets additional options that are appended the the tool command-line. 18 /// Gets or sets additional options that are appended the the tool command-line.
@@ -27,6 +29,12 @@ namespace WixToolset.BuildTasks
27 public bool NoLogo { get; set; } 29 public bool NoLogo { get; set; }
28 30
29 /// <summary> 31 /// <summary>
32 /// Gets or sets a flag indicating whether the task
33 /// should be run as separate process or in-proc.
34 /// </summary>
35 public bool RunAsSeparateProcess { get; set; }
36
37 /// <summary>
30 /// Gets or sets whether all warnings should be suppressed. 38 /// Gets or sets whether all warnings should be suppressed.
31 /// </summary> 39 /// </summary>
32 public bool SuppressAllWarnings { get; set; } 40 public bool SuppressAllWarnings { get; set; }
@@ -51,19 +59,27 @@ namespace WixToolset.BuildTasks
51 /// </summary> 59 /// </summary>
52 public bool VerboseOutput { get; set; } 60 public bool VerboseOutput { get; set; }
53 61
54 public override bool Execute() 62 protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
55 { 63 {
56 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); 64 if (this.RunAsSeparateProcess)
65 {
66 return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
67 }
68
69 return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}");
70 }
57 71
72 private int ExecuteInProc(string commandLineString)
73 {
74 this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}");
75
76 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
58 var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode); 77 var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode);
78 int exitCode = -1;
59 79
60 try 80 try
61 { 81 {
62 var commandLineBuilder = new WixCommandLineBuilder(); 82 exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString);
63 this.BuildCommandLine(commandLineBuilder);
64
65 var commandLineString = commandLineBuilder.ToString();
66 this.ExecuteCore(serviceProvider, listener, commandLineString);
67 } 83 }
68 catch (WixException e) 84 catch (WixException e)
69 { 85 {
@@ -79,7 +95,47 @@ namespace WixToolset.BuildTasks
79 } 95 }
80 } 96 }
81 97
82 return !this.Log.HasLoggedErrors; 98 if (exitCode == 0 && this.Log.HasLoggedErrors)
99 {
100 exitCode = -1;
101 }
102 return exitCode;
103 }
104
105 /// <summary>
106 /// Get the path to the executable.
107 /// </summary>
108 /// <remarks>
109 /// ToolTask only calls GenerateFullPathToTool when the ToolPath property is not set.
110 /// WiX never sets the ToolPath property, but the user can through $(WixToolDir).
111 /// If we return only a file name, ToolTask will search the system paths for it.
112 /// </remarks>
113 protected sealed override string GenerateFullPathToTool()
114 {
115 var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath;
116 if (this.RunAsSeparateProcess)
117 {
118 return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe);
119 }
120
121 // 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.
122 return thisDllPath;
123 }
124
125 protected sealed override string GenerateResponseFileCommands()
126 {
127 var commandLineBuilder = new WixCommandLineBuilder();
128 this.BuildCommandLine(commandLineBuilder);
129 return commandLineBuilder.ToString();
130 }
131
132 protected sealed override void LogToolCommand(string message)
133 {
134 // Only log this if we're actually going to do it.
135 if (this.RunAsSeparateProcess)
136 {
137 base.LogToolCommand(message);
138 }
83 } 139 }
84 140
85 /// <summary> 141 /// <summary>
@@ -98,7 +154,7 @@ namespace WixToolset.BuildTasks
98 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); 154 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors);
99 } 155 }
100 156
101 protected abstract void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString); 157 protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString);
102 158
103 protected abstract string TaskShortName { get; } 159 protected abstract string TaskShortName { get; }
104 } 160 }