diff options
Diffstat (limited to 'src/WixToolset.BuildTasks/ToolsetTask_InProc.cs')
-rw-r--r-- | src/WixToolset.BuildTasks/ToolsetTask_InProc.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs new file mode 100644 index 00000000..4b365b2a --- /dev/null +++ b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs | |||
@@ -0,0 +1,71 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.BuildTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Runtime.InteropServices; | ||
7 | using Microsoft.Build.Framework; | ||
8 | using WixToolset.Core; | ||
9 | using WixToolset.Data; | ||
10 | using WixToolset.Extensibility; | ||
11 | using WixToolset.Extensibility.Services; | ||
12 | |||
13 | public partial class ToolsetTask | ||
14 | { | ||
15 | protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) | ||
16 | { | ||
17 | if (this.RunAsSeparateProcess) | ||
18 | { | ||
19 | return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands); | ||
20 | } | ||
21 | |||
22 | return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}"); | ||
23 | } | ||
24 | |||
25 | private int ExecuteInProc(string commandLineString) | ||
26 | { | ||
27 | this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}"); | ||
28 | |||
29 | var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); | ||
30 | var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode); | ||
31 | int exitCode = -1; | ||
32 | |||
33 | try | ||
34 | { | ||
35 | exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString); | ||
36 | } | ||
37 | catch (WixException e) | ||
38 | { | ||
39 | listener.Write(e.Error); | ||
40 | } | ||
41 | catch (Exception e) | ||
42 | { | ||
43 | this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null); | ||
44 | |||
45 | if (e is NullReferenceException || e is SEHException) | ||
46 | { | ||
47 | throw; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | if (exitCode == 0 && this.Log.HasLoggedErrors) | ||
52 | { | ||
53 | exitCode = -1; | ||
54 | } | ||
55 | return exitCode; | ||
56 | } | ||
57 | |||
58 | protected sealed override void LogToolCommand(string message) | ||
59 | { | ||
60 | // Only log this if we're actually going to do it. | ||
61 | if (this.RunAsSeparateProcess) | ||
62 | { | ||
63 | base.LogToolCommand(message); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString); | ||
68 | |||
69 | protected abstract string TaskShortName { get; } | ||
70 | } | ||
71 | } | ||