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.cs73
1 files changed, 5 insertions, 68 deletions
diff --git a/src/WixToolset.BuildTasks/ToolsetTask.cs b/src/WixToolset.BuildTasks/ToolsetTask.cs
index fe6812fc..4fd7af3f 100644
--- a/src/WixToolset.BuildTasks/ToolsetTask.cs
+++ b/src/WixToolset.BuildTasks/ToolsetTask.cs
@@ -4,15 +4,9 @@ namespace WixToolset.BuildTasks
4{ 4{
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using System.Runtime.InteropServices;
8 using Microsoft.Build.Framework;
9 using Microsoft.Build.Utilities; 7 using Microsoft.Build.Utilities;
10 using WixToolset.Core;
11 using WixToolset.Data;
12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
14 8
15 public abstract class ToolsetTask : ToolTask 9 public abstract partial class ToolsetTask : ToolTask
16 { 10 {
17 /// <summary> 11 /// <summary>
18 /// Gets or sets additional options that are appended the the tool command-line. 12 /// Gets or sets additional options that are appended the the tool command-line.
@@ -59,49 +53,6 @@ namespace WixToolset.BuildTasks
59 /// </summary> 53 /// </summary>
60 public bool VerboseOutput { get; set; } 54 public bool VerboseOutput { get; set; }
61 55
62 protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
63 {
64 if (this.RunAsSeparateProcess)
65 {
66 return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
67 }
68
69 return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}");
70 }
71
72 private int ExecuteInProc(string commandLineString)
73 {
74 this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}");
75
76 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
77 var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode);
78 int exitCode = -1;
79
80 try
81 {
82 exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString);
83 }
84 catch (WixException e)
85 {
86 listener.Write(e.Error);
87 }
88 catch (Exception e)
89 {
90 this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null);
91
92 if (e is NullReferenceException || e is SEHException)
93 {
94 throw;
95 }
96 }
97
98 if (exitCode == 0 && this.Log.HasLoggedErrors)
99 {
100 exitCode = -1;
101 }
102 return exitCode;
103 }
104
105 /// <summary> 56 /// <summary>
106 /// Get the path to the executable. 57 /// Get the path to the executable.
107 /// </summary> 58 /// </summary>
@@ -113,13 +64,12 @@ namespace WixToolset.BuildTasks
113 protected sealed override string GenerateFullPathToTool() 64 protected sealed override string GenerateFullPathToTool()
114 { 65 {
115 var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; 66 var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath;
116 if (this.RunAsSeparateProcess) 67 if (!this.RunAsSeparateProcess)
117 { 68 {
118 return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe); 69 // 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.
70 return thisDllPath;
119 } 71 }
120 72 return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe);
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 } 73 }
124 74
125 protected sealed override string GenerateResponseFileCommands() 75 protected sealed override string GenerateResponseFileCommands()
@@ -129,15 +79,6 @@ namespace WixToolset.BuildTasks
129 return commandLineBuilder.ToString(); 79 return commandLineBuilder.ToString();
130 } 80 }
131 81
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 }
139 }
140
141 /// <summary> 82 /// <summary>
142 /// Builds a command line from options in this and derivative tasks. 83 /// Builds a command line from options in this and derivative tasks.
143 /// </summary> 84 /// </summary>
@@ -153,9 +94,5 @@ namespace WixToolset.BuildTasks
153 commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); 94 commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors);
154 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); 95 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors);
155 } 96 }
156
157 protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString);
158
159 protected abstract string TaskShortName { get; }
160 } 97 }
161} 98}