aboutsummaryrefslogtreecommitdiff
path: root/src/tools/heat/Program.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-07-26 17:20:39 -0700
committerRob Mensching <rob@firegiant.com>2022-08-01 20:25:19 -0700
commita627ca9b720047e633a8fe72003ab9bee31006c5 (patch)
tree2bc8a924bb4141ab718e74d08f6459a0ffe8d573 /src/tools/heat/Program.cs
parent521eb3c9cf38823a2c4019abb85dc0b3200b92cb (diff)
downloadwix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.gz
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.bz2
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.zip
Create WixToolset.Heat.nupkg to distribute heat.exe and Heat targets
Moves Heat functionality to the "tools" layer and packages it all up in WixToolset.Heat.nupkg for distribution in WiX v4. Completes 6838
Diffstat (limited to 'src/tools/heat/Program.cs')
-rw-r--r--src/tools/heat/Program.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/tools/heat/Program.cs b/src/tools/heat/Program.cs
new file mode 100644
index 00000000..f74def8f
--- /dev/null
+++ b/src/tools/heat/Program.cs
@@ -0,0 +1,84 @@
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
3namespace WixToolset.Tools.Heat
4{
5 using System;
6 using System.Runtime.InteropServices;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using WixToolset.Core;
10 using WixToolset.Data;
11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Data;
13 using WixToolset.Extensibility.Services;
14 using WixToolset.Harvesters;
15 using WixToolset.Harvesters.Extensibility;
16 using WixToolset.Tools.Core;
17
18 /// <summary>
19 /// Wix Toolset Harvester.
20 /// </summary>
21 public sealed class Program
22 {
23 /// <summary>
24 /// The main entry point for the application.
25 /// </summary>
26 /// <param name="args">Commandline arguments for the application.</param>
27 /// <returns>Returns the application error code.</returns>
28 [MTAThread]
29 public static async Task<int> Main(string[] args)
30 {
31 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
32 var listener = new ConsoleMessageListener("HEAT", "heat.exe");
33
34 try
35 {
36 var program = new Program();
37 return await program.Run(serviceProvider, listener, args);
38 }
39 catch (WixException e)
40 {
41 listener.Write(e.Error);
42
43 return e.Error.Id;
44 }
45 catch (Exception e)
46 {
47 listener.Write(ErrorMessages.UnexpectedException(e));
48
49 if (e is NullReferenceException || e is SEHException)
50 {
51 throw;
52 }
53
54 return e.HResult;
55 }
56 }
57
58 /// <summary>
59 /// Run the application with the given arguments.
60 /// </summary>
61 /// <param name="serviceProvider">Service provider to use throughout this execution.</param>
62 /// <param name="args">The commandline arguments.</param>
63 /// <returns>Returns the application error code.</returns>
64 public Task<int> Run(IServiceProvider serviceProvider, IMessageListener listener, string[] args)
65 {
66 var messaging = serviceProvider.GetService<IMessaging>();
67 messaging.SetListener(listener);
68
69 var arguments = serviceProvider.GetService<ICommandLineArguments>();
70 arguments.Populate(args);
71
72 var extensionManager = serviceProvider.GetService<IExtensionManager>();
73 foreach (var extension in arguments.Extensions)
74 {
75 extensionManager.Load(extension);
76 }
77 var heatExtensions = extensionManager.GetServices<IHeatExtension>();
78
79 var commandLine = HeatCommandLineFactory.CreateCommandLine(serviceProvider, heatExtensions);
80 var command = commandLine.ParseStandardCommandLine(arguments);
81 return command?.ExecuteAsync(CancellationToken.None) ?? Task.FromResult(1);
82 }
83 }
84}