aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Directory.Build.props3
-rw-r--r--src/WixToolset.BuildTasks/DoIt.cs23
-rw-r--r--src/WixToolset.Core.Burn/BackendFactory.cs1
-rw-r--r--src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs1
-rw-r--r--src/WixToolset.Core.Burn/BundleBackend.cs1
-rw-r--r--src/WixToolset.Core.Burn/StandardBackend.cs12
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/MsiBackend.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/MsmBackend.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/MspBackend.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/MstBackend.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/StandardBackend.cs12
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Validator.cs1
-rw-r--r--src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs1
-rw-r--r--src/WixToolset.Core/BindContext.cs9
-rw-r--r--src/WixToolset.Core/Binder.cs5
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs10
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs64
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineContext.cs26
-rw-r--r--src/WixToolset.Core/CommandLine/CompileCommand.cs3
-rw-r--r--src/WixToolset.Core/CommandLine/HelpCommand.cs1
-rw-r--r--src/WixToolset.Core/CommandLine/ICommandLineCommand.cs9
-rw-r--r--src/WixToolset.Core/CommandLine/VersionCommand.cs5
-rw-r--r--src/WixToolset.Core/ExtensionManager.cs18
-rw-r--r--src/WixToolset.Core/IncribeContext.cs8
-rw-r--r--src/WixToolset.Core/WixToolsetServiceProvider.cs47
-rw-r--r--src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs2
-rw-r--r--src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj25
-rw-r--r--src/wix/Program.cs32
29 files changed, 242 insertions, 82 deletions
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index b27b5ca8..7cd6767f 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -5,7 +5,8 @@
5 <PropertyGroup> 5 <PropertyGroup>
6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7 <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\build\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath> 7 <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\build\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
8 <OutputPath>$(MSBuildThisFileDirectory)..\build\$(Configuration)\</OutputPath> 8 <BaseOutputPath>$(MSBuildThisFileDirectory)..\build\$(Configuration)\</BaseOutputPath>
9 <OutputPath>$(BaseOutputPath)</OutputPath>
9 10
10 <Authors>WiX Toolset Team</Authors> 11 <Authors>WiX Toolset Team</Authors>
11 <Company>WiX Toolset</Company> 12 <Company>WiX Toolset</Company>
diff --git a/src/WixToolset.BuildTasks/DoIt.cs b/src/WixToolset.BuildTasks/DoIt.cs
index d3bd7a80..924bf92f 100644
--- a/src/WixToolset.BuildTasks/DoIt.cs
+++ b/src/WixToolset.BuildTasks/DoIt.cs
@@ -9,6 +9,7 @@ namespace WixToolset.BuildTasks
9 using Microsoft.Build.Utilities; 9 using Microsoft.Build.Utilities;
10 using WixToolset.Core; 10 using WixToolset.Core;
11 using WixToolset.Data; 11 using WixToolset.Data;
12 using WixToolset.Extensibility.Services;
12 13
13 /// <summary> 14 /// <summary>
14 /// An MSBuild task to run the WiX compiler. 15 /// An MSBuild task to run the WiX compiler.
@@ -164,10 +165,30 @@ namespace WixToolset.BuildTasks
164 165
165 this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString); 166 this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString);
166 167
167 var command = CommandLine.ParseStandardCommandLine(commandLineString); 168 var serviceProvider = new WixToolsetServiceProvider();
169
170 var context = serviceProvider.GetService<ICommandLineContext>();
171 context.Messaging = Messaging.Instance;
172 context.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider);
173 context.Arguments = commandLineString;
174
175 var commandLine = serviceProvider.GetService<ICommandLine>();
176 var command = commandLine.ParseStandardCommandLine(context);
168 command?.Execute(); 177 command?.Execute();
169 } 178 }
170 179
180 private IExtensionManager CreateExtensionManagerWithStandardBackends(IServiceProvider serviceProvider)
181 {
182 var extensionManager = serviceProvider.GetService<IExtensionManager>();
183
184 foreach (var type in new[] { typeof(WixToolset.Core.Burn.StandardBackend), typeof(WixToolset.Core.WindowsInstaller.StandardBackend) })
185 {
186 extensionManager.Add(type.Assembly);
187 }
188
189 return extensionManager;
190 }
191
171 private void DisplayMessage(object sender, DisplayEventArgs e) 192 private void DisplayMessage(object sender, DisplayEventArgs e)
172 { 193 {
173 this.Log.LogMessageFromText(e.Message, MessageImportance.Normal); 194 this.Log.LogMessageFromText(e.Message, MessageImportance.Normal);
diff --git a/src/WixToolset.Core.Burn/BackendFactory.cs b/src/WixToolset.Core.Burn/BackendFactory.cs
index 042fa254..a69c47b5 100644
--- a/src/WixToolset.Core.Burn/BackendFactory.cs
+++ b/src/WixToolset.Core.Burn/BackendFactory.cs
@@ -5,6 +5,7 @@ namespace WixToolset.Core.Burn
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using WixToolset.Extensibility; 7 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Services;
8 9
9 internal class BackendFactory : IBackendFactory 10 internal class BackendFactory : IBackendFactory
10 { 11 {
diff --git a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
index 212b1e81..3934491b 100644
--- a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
+++ b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
@@ -16,6 +16,7 @@ namespace WixToolset.Core.Burn
16 using WixToolset.Data.Bind; 16 using WixToolset.Data.Bind;
17 using WixToolset.Data.Rows; 17 using WixToolset.Data.Rows;
18 using WixToolset.Extensibility; 18 using WixToolset.Extensibility;
19 using WixToolset.Extensibility.Services;
19 20
20 // TODO: (4.0) Refactor so that these don't need to be copied. 21 // TODO: (4.0) Refactor so that these don't need to be copied.
21 // Copied verbatim from ext\UtilExtension\wixext\UtilCompiler.cs 22 // Copied verbatim from ext\UtilExtension\wixext\UtilCompiler.cs
diff --git a/src/WixToolset.Core.Burn/BundleBackend.cs b/src/WixToolset.Core.Burn/BundleBackend.cs
index ef4d362c..0c7f2e8b 100644
--- a/src/WixToolset.Core.Burn/BundleBackend.cs
+++ b/src/WixToolset.Core.Burn/BundleBackend.cs
@@ -9,6 +9,7 @@ namespace WixToolset.Core.Burn
9 using WixToolset.Data; 9 using WixToolset.Data;
10 using WixToolset.Data.Bind; 10 using WixToolset.Data.Bind;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
12 13
13 internal class BundleBackend : IBackend 14 internal class BundleBackend : IBackend
14 { 15 {
diff --git a/src/WixToolset.Core.Burn/StandardBackend.cs b/src/WixToolset.Core.Burn/StandardBackend.cs
new file mode 100644
index 00000000..2ab30776
--- /dev/null
+++ b/src/WixToolset.Core.Burn/StandardBackend.cs
@@ -0,0 +1,12 @@
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.Core.Burn
4{
5 /// <summary>
6 /// Denotes this assembly contains a backend that is considered
7 /// a standard part of the WiX Toolset.
8 /// </summary>
9 public static class StandardBackend
10 {
11 }
12}
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
index 2e2c5417..21fbb022 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
@@ -16,6 +16,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
16 using WixToolset.Data.Bind; 16 using WixToolset.Data.Bind;
17 using WixToolset.Data.Rows; 17 using WixToolset.Data.Rows;
18 using WixToolset.Extensibility; 18 using WixToolset.Extensibility;
19 using WixToolset.Extensibility.Services;
19 using WixToolset.Msi; 20 using WixToolset.Msi;
20 21
21 /// <summary> 22 /// <summary>
diff --git a/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs b/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs
index 716ea000..bf7b4579 100644
--- a/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs
+++ b/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs
@@ -8,6 +8,7 @@ namespace WixToolset.Core.WindowsInstaller
8 using WixToolset.Data; 8 using WixToolset.Data;
9 using WixToolset.Data.Bind; 9 using WixToolset.Data.Bind;
10 using WixToolset.Extensibility; 10 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services;
11 12
12 internal class MsiBackend : IBackend 13 internal class MsiBackend : IBackend
13 { 14 {
diff --git a/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs b/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs
index 268213d7..69d7ada0 100644
--- a/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs
+++ b/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs
@@ -7,6 +7,7 @@ namespace WixToolset.Core.WindowsInstaller
7 using WixToolset.Data; 7 using WixToolset.Data;
8 using WixToolset.Data.Bind; 8 using WixToolset.Data.Bind;
9 using WixToolset.Extensibility; 9 using WixToolset.Extensibility;
10 using WixToolset.Extensibility.Services;
10 11
11 internal class MsmBackend : IBackend 12 internal class MsmBackend : IBackend
12 { 13 {
diff --git a/src/WixToolset.Core.WindowsInstaller/MspBackend.cs b/src/WixToolset.Core.WindowsInstaller/MspBackend.cs
index 4b13258b..ea16a570 100644
--- a/src/WixToolset.Core.WindowsInstaller/MspBackend.cs
+++ b/src/WixToolset.Core.WindowsInstaller/MspBackend.cs
@@ -10,6 +10,7 @@ namespace WixToolset.Core.WindowsInstaller
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Data.Bind; 11 using WixToolset.Data.Bind;
12 using WixToolset.Extensibility; 12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
13 using WixToolset.Msi; 14 using WixToolset.Msi;
14 using WixToolset.Ole32; 15 using WixToolset.Ole32;
15 16
diff --git a/src/WixToolset.Core.WindowsInstaller/MstBackend.cs b/src/WixToolset.Core.WindowsInstaller/MstBackend.cs
index 2cb7da89..66bc57ae 100644
--- a/src/WixToolset.Core.WindowsInstaller/MstBackend.cs
+++ b/src/WixToolset.Core.WindowsInstaller/MstBackend.cs
@@ -8,6 +8,7 @@ namespace WixToolset.Core.WindowsInstaller
8 using WixToolset.Data; 8 using WixToolset.Data;
9 using WixToolset.Data.Bind; 9 using WixToolset.Data.Bind;
10 using WixToolset.Extensibility; 10 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services;
11 12
12 internal class MstBackend : IBackend 13 internal class MstBackend : IBackend
13 { 14 {
diff --git a/src/WixToolset.Core.WindowsInstaller/StandardBackend.cs b/src/WixToolset.Core.WindowsInstaller/StandardBackend.cs
new file mode 100644
index 00000000..f1ae2017
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/StandardBackend.cs
@@ -0,0 +1,12 @@
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.Core.WindowsInstaller
4{
5 /// <summary>
6 /// Denotes this assembly contains a backend that is considered
7 /// a standard part of the WiX Toolset.
8 /// </summary>
9 public static class StandardBackend
10 {
11 }
12}
diff --git a/src/WixToolset.Core.WindowsInstaller/Validator.cs b/src/WixToolset.Core.WindowsInstaller/Validator.cs
index db66f600..652a8a07 100644
--- a/src/WixToolset.Core.WindowsInstaller/Validator.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Validator.cs
@@ -16,6 +16,7 @@ namespace WixToolset.Core.WindowsInstaller
16 using WixToolset.Msi; 16 using WixToolset.Msi;
17 using System.Linq; 17 using System.Linq;
18 using System.Reflection; 18 using System.Reflection;
19 using WixToolset.Extensibility.Services;
19 20
20 /// <summary> 21 /// <summary>
21 /// Runs internal consistency evaluators (ICEs) from cub files against a database. 22 /// Runs internal consistency evaluators (ICEs) from cub files against a database.
diff --git a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs
index b66a4617..a7f58ed4 100644
--- a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs
+++ b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs
@@ -5,6 +5,7 @@ namespace WixToolset.Core.WindowsInstaller
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using WixToolset.Extensibility; 7 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Services;
8 9
9 internal class WindowsInstallerBackendFactory : IBackendFactory 10 internal class WindowsInstallerBackendFactory : IBackendFactory
10 { 11 {
diff --git a/src/WixToolset.Core/BindContext.cs b/src/WixToolset.Core/BindContext.cs
index 499f3245..7b1a1877 100644
--- a/src/WixToolset.Core/BindContext.cs
+++ b/src/WixToolset.Core/BindContext.cs
@@ -2,12 +2,21 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
5 using System.Collections.Generic; 6 using System.Collections.Generic;
6 using WixToolset.Data; 7 using WixToolset.Data;
7 using WixToolset.Extensibility; 8 using WixToolset.Extensibility;
9 using WixToolset.Extensibility.Services;
8 10
9 public class BindContext : IBindContext 11 public class BindContext : IBindContext
10 { 12 {
13 internal BindContext(IServiceProvider serviceProvider)
14 {
15 this.ServiceProvider = serviceProvider;
16 }
17
18 public IServiceProvider ServiceProvider { get; }
19
11 public Messaging Messaging { get; set; } 20 public Messaging Messaging { get; set; }
12 21
13 public IEnumerable<BindPath> BindPaths { get; set; } 22 public IEnumerable<BindPath> BindPaths { get; set; }
diff --git a/src/WixToolset.Core/Binder.cs b/src/WixToolset.Core/Binder.cs
index 43c15634..34bf0dee 100644
--- a/src/WixToolset.Core/Binder.cs
+++ b/src/WixToolset.Core/Binder.cs
@@ -16,6 +16,7 @@ namespace WixToolset.Core
16 using WixToolset.Data.Bind; 16 using WixToolset.Data.Bind;
17 using WixToolset.Data.Rows; 17 using WixToolset.Data.Rows;
18 using WixToolset.Extensibility; 18 using WixToolset.Extensibility;
19 using WixToolset.Extensibility.Services;
19 20
20 /// <summary> 21 /// <summary>
21 /// Binder of the WiX toolset. 22 /// Binder of the WiX toolset.
@@ -42,14 +43,14 @@ namespace WixToolset.Core
42 //this.SuppressIces = new List<string>(); 43 //this.SuppressIces = new List<string>();
43 } 44 }
44 45
45 public Binder(BindContext context) 46 public Binder(IBindContext context)
46 { 47 {
47 this.Context = context; 48 this.Context = context;
48 49
49 this.TableDefinitions = WindowsInstallerStandard.GetTableDefinitions(); 50 this.TableDefinitions = WindowsInstallerStandard.GetTableDefinitions();
50 } 51 }
51 52
52 private BindContext Context { get; } 53 private IBindContext Context { get; }
53 54
54 private TableDefinitionCollection TableDefinitions { get; } 55 private TableDefinitionCollection TableDefinitions { get; }
55 56
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index b3909451..4a1fc1ed 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -9,11 +9,13 @@ namespace WixToolset.Core
9 using WixToolset.Data; 9 using WixToolset.Data;
10 using WixToolset.Data.Rows; 10 using WixToolset.Data.Rows;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
12 13
13 internal class BuildCommand : ICommandLineCommand 14 internal class BuildCommand : ICommandLineCommand
14 { 15 {
15 public BuildCommand(ExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) 16 public BuildCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile)
16 { 17 {
18 this.ServiceProvider = serviceProvider;
17 this.ExtensionManager = extensions; 19 this.ExtensionManager = extensions;
18 this.LocFiles = locFiles; 20 this.LocFiles = locFiles;
19 this.LibraryFiles = libraryFiles; 21 this.LibraryFiles = libraryFiles;
@@ -34,7 +36,9 @@ namespace WixToolset.Core
34 this.WixProjectFile = wixProjectFile; 36 this.WixProjectFile = wixProjectFile;
35 } 37 }
36 38
37 public ExtensionManager ExtensionManager { get; } 39 public IServiceProvider ServiceProvider { get; }
40
41 public IExtensionManager ExtensionManager { get; }
38 42
39 public IEnumerable<string> LocFiles { get; } 43 public IEnumerable<string> LocFiles { get; }
40 44
@@ -173,7 +177,7 @@ namespace WixToolset.Core
173 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); 177 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
174 } 178 }
175 179
176 var context = new BindContext(); 180 var context = this.ServiceProvider.GetService<IBindContext>();
177 context.Messaging = Messaging.Instance; 181 context.Messaging = Messaging.Instance;
178 context.ExtensionManager = this.ExtensionManager; 182 context.ExtensionManager = this.ExtensionManager;
179 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>(); 183 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>();
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 2f203ecb..b0594348 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -6,11 +6,11 @@ namespace WixToolset.Core
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Linq; 8 using System.Linq;
9 using System.Reflection;
10 using System.Text; 9 using System.Text;
11 using System.Text.RegularExpressions; 10 using System.Text.RegularExpressions;
12 using WixToolset.Data; 11 using WixToolset.Data;
13 using WixToolset.Extensibility; 12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
14 14
15 internal enum Commands 15 internal enum Commands
16 { 16 {
@@ -22,12 +22,14 @@ namespace WixToolset.Core
22 Bind, 22 Bind,
23 } 23 }
24 24
25 public class CommandLine 25 internal class CommandLine : ICommandLine
26 { 26 {
27 private CommandLine() 27 public CommandLine()
28 { 28 {
29 } 29 }
30 30
31 private IServiceProvider ServiceProvider { get; set; }
32
31 public static string ExpectedArgument { get; } = "expected argument"; 33 public static string ExpectedArgument { get; } = "expected argument";
32 34
33 public string ActiveCommand { get; private set; } 35 public string ActiveCommand { get; private set; }
@@ -36,20 +38,29 @@ namespace WixToolset.Core
36 38
37 public Queue<string> RemainingArguments { get; } = new Queue<string>(); 39 public Queue<string> RemainingArguments { get; } = new Queue<string>();
38 40
39 public ExtensionManager ExtensionManager { get; } = new ExtensionManager(); 41 public IExtensionManager ExtensionManager { get; private set; }
40 42
41 public string ErrorArgument { get; set; } 43 public string ErrorArgument { get; set; }
42 44
43 public bool ShowHelp { get; set; } 45 public bool ShowHelp { get; set; }
44 46
45 public static ICommandLineCommand ParseStandardCommandLine(string commandLineString) 47 public ICommandLineCommand ParseStandardCommandLine(ICommandLineContext context)
46 { 48 {
47 var args = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); 49 this.ServiceProvider = context.ServiceProvider;
50
51 this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>();
52
53 var args = context.ParsedArguments ?? Array.Empty<string>();
54
55 if (!String.IsNullOrEmpty(context.Arguments))
56 {
57 args = CommandLine.ParseArgumentsToArray(context.Arguments).Union(args).ToArray();
58 }
48 59
49 return ParseStandardCommandLine(args); 60 return this.ParseStandardCommandLine(args);
50 } 61 }
51 62
52 public static ICommandLineCommand ParseStandardCommandLine(string[] args) 63 private ICommandLineCommand ParseStandardCommandLine(string[] args)
53 { 64 {
54 var next = String.Empty; 65 var next = String.Empty;
55 66
@@ -79,7 +90,7 @@ namespace WixToolset.Core
79 var builtOutputsFile = String.Empty; 90 var builtOutputsFile = String.Empty;
80 var wixProjectFile = String.Empty; 91 var wixProjectFile = String.Empty;
81 92
82 var cli = CommandLine.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => 93 this.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) =>
83 { 94 {
84 if (cmdline.IsSwitch(arg)) 95 if (cmdline.IsSwitch(arg))
85 { 96 {
@@ -103,7 +114,7 @@ namespace WixToolset.Core
103 case "cc": 114 case "cc":
104 cmdline.GetNextArgumentOrError(ref cabCachePath); 115 cmdline.GetNextArgumentOrError(ref cabCachePath);
105 return true; 116 return true;
106 117
107 case "cultures": 118 case "cultures":
108 cmdline.GetNextArgumentOrError(cultures); 119 cmdline.GetNextArgumentOrError(cultures);
109 return true; 120 return true;
@@ -187,7 +198,7 @@ namespace WixToolset.Core
187 AppCommon.DisplayToolHeader(); 198 AppCommon.DisplayToolHeader();
188 } 199 }
189 200
190 if (cli.ShowHelp) 201 if (this.ShowHelp)
191 { 202 {
192 return new HelpCommand(command); 203 return new HelpCommand(command);
193 } 204 }
@@ -196,14 +207,11 @@ namespace WixToolset.Core
196 { 207 {
197 case Commands.Build: 208 case Commands.Build:
198 { 209 {
199 LoadStandardBackends(cli.ExtensionManager);
200
201 var sourceFiles = GatherSourceFiles(files, outputFolder); 210 var sourceFiles = GatherSourceFiles(files, outputFolder);
202 var variables = GatherPreprocessorVariables(defines); 211 var variables = GatherPreprocessorVariables(defines);
203 var bindPathList = GatherBindPaths(bindPaths); 212 var bindPathList = GatherBindPaths(bindPaths);
204 var extensions = cli.ExtensionManager;
205 var type = CalculateOutputType(outputType, outputFile); 213 var type = CalculateOutputType(outputType, outputFile);
206 return new BuildCommand(extensions, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); 214 return new BuildCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile);
207 } 215 }
208 216
209 case Commands.Compile: 217 case Commands.Compile:
@@ -217,18 +225,6 @@ namespace WixToolset.Core
217 return null; 225 return null;
218 } 226 }
219 227
220 private static void LoadStandardBackends(ExtensionManager extensionManager)
221 {
222 var folder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
223
224 foreach (var backendAssemblyName in new[] { "WixToolset.Core.Burn.dll", "WixToolset.Core.WindowsInstaller.dll" })
225 {
226 var path = Path.Combine(folder, backendAssemblyName);
227
228 extensionManager.Load(path);
229 }
230 }
231
232 private static OutputType CalculateOutputType(string outputType, string outputFile) 228 private static OutputType CalculateOutputType(string outputType, string outputFile)
233 { 229 {
234 if (String.IsNullOrEmpty(outputType)) 230 if (String.IsNullOrEmpty(outputType))
@@ -269,6 +265,7 @@ namespace WixToolset.Core
269 return OutputType.Unknown; 265 return OutputType.Unknown;
270 } 266 }
271 267
268#if UNUSED
272 private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument) 269 private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument)
273 { 270 {
274 var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); 271 var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray();
@@ -280,18 +277,17 @@ namespace WixToolset.Core
280 { 277 {
281 return CommandLine.Parse(commandLineArguments, null, parseArgument); 278 return CommandLine.Parse(commandLineArguments, null, parseArgument);
282 } 279 }
280#endif
283 281
284 private static CommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument) 282 private ICommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument)
285 { 283 {
286 var cmdline = new CommandLine(); 284 this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments);
287
288 cmdline.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments);
289 285
290 cmdline.QueueArgumentsAndLoadExtensions(cmdline.OriginalArguments); 286 this.QueueArgumentsAndLoadExtensions(this.OriginalArguments);
291 287
292 cmdline.ProcessRemainingArguments(parseArgument, parseCommand); 288 this.ProcessRemainingArguments(parseArgument, parseCommand);
293 289
294 return cmdline; 290 return this;
295 } 291 }
296 292
297 private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory) 293 private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory)
diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
new file mode 100644
index 00000000..96c149be
--- /dev/null
+++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
@@ -0,0 +1,26 @@
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.Core
4{
5 using System;
6 using WixToolset.Data;
7 using WixToolset.Extensibility.Services;
8
9 internal class CommandLineContext : ICommandLineContext
10 {
11 public CommandLineContext(IServiceProvider serviceProvider)
12 {
13 this.ServiceProvider = serviceProvider;
14 }
15
16 public IServiceProvider ServiceProvider { get; }
17
18 public Messaging Messaging { get; set; }
19
20 public IExtensionManager ExtensionManager { get; set; }
21
22 public string Arguments { get; set; }
23
24 public string[] ParsedArguments { get; set; }
25 }
26}
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs
index bbcc8270..855e7c6a 100644
--- a/src/WixToolset.Core/CommandLine/CompileCommand.cs
+++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs
@@ -2,9 +2,8 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
6 using System.Collections.Generic; 5 using System.Collections.Generic;
7 using WixToolset.Data; 6 using WixToolset.Extensibility.Services;
8 7
9 internal class CompileCommand : ICommandLineCommand 8 internal class CompileCommand : ICommandLineCommand
10 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/HelpCommand.cs b/src/WixToolset.Core/CommandLine/HelpCommand.cs
index e57ad132..2a2eab24 100644
--- a/src/WixToolset.Core/CommandLine/HelpCommand.cs
+++ b/src/WixToolset.Core/CommandLine/HelpCommand.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using WixToolset.Extensibility.Services;
6 7
7 internal class HelpCommand : ICommandLineCommand 8 internal class HelpCommand : ICommandLineCommand
8 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs b/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
deleted file mode 100644
index f1471355..00000000
--- a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
+++ /dev/null
@@ -1,9 +0,0 @@
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.Core
4{
5 public interface ICommandLineCommand
6 {
7 int Execute();
8 }
9}
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs
index d13e07a3..12941bdc 100644
--- a/src/WixToolset.Core/CommandLine/VersionCommand.cs
+++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs
@@ -1,9 +1,10 @@
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. 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 2
3using System;
4
5namespace WixToolset.Core 3namespace WixToolset.Core
6{ 4{
5 using System;
6 using WixToolset.Extensibility.Services;
7
7 internal class VersionCommand : ICommandLineCommand 8 internal class VersionCommand : ICommandLineCommand
8 { 9 {
9 public int Execute() 10 public int Execute()
diff --git a/src/WixToolset.Core/ExtensionManager.cs b/src/WixToolset.Core/ExtensionManager.cs
index 7e40571b..b9038c6a 100644
--- a/src/WixToolset.Core/ExtensionManager.cs
+++ b/src/WixToolset.Core/ExtensionManager.cs
@@ -1,6 +1,6 @@
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. 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 2
3namespace WixToolset 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
@@ -8,13 +8,24 @@ namespace WixToolset
8 using System.Linq; 8 using System.Linq;
9 using System.Reflection; 9 using System.Reflection;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility.Services;
12 12
13 public class ExtensionManager : IExtensionManager 13 public class ExtensionManager : IExtensionManager
14 { 14 {
15 private List<Assembly> extensionAssemblies = new List<Assembly>(); 15 private List<Assembly> extensionAssemblies = new List<Assembly>();
16 16
17 /// <summary> 17 /// <summary>
18 /// Adds an assembly.
19 /// </summary>
20 /// <param name="assembly">Assembly to add to the extension manager.</param>
21 /// <returns>The assembly added.</returns>
22 public Assembly Add(Assembly assembly)
23 {
24 this.extensionAssemblies.Add(assembly);
25 return assembly;
26 }
27
28 /// <summary>
18 /// Loads an assembly from a type description string. 29 /// Loads an assembly from a type description string.
19 /// </summary> 30 /// </summary>
20 /// <param name="extension">The assembly type description string.</param> 31 /// <param name="extension">The assembly type description string.</param>
@@ -57,8 +68,7 @@ namespace WixToolset
57 assembly = ExtensionManager.ExtensionLoadFrom(assemblyName); 68 assembly = ExtensionManager.ExtensionLoadFrom(assemblyName);
58 } 69 }
59 70
60 this.extensionAssemblies.Add(assembly); 71 return this.Add(assembly);
61 return assembly;
62 } 72 }
63 73
64 /// <summary> 74 /// <summary>
diff --git a/src/WixToolset.Core/IncribeContext.cs b/src/WixToolset.Core/IncribeContext.cs
index 604ba5d1..15dd3664 100644
--- a/src/WixToolset.Core/IncribeContext.cs
+++ b/src/WixToolset.Core/IncribeContext.cs
@@ -2,11 +2,19 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
5 using WixToolset.Data; 6 using WixToolset.Data;
6 using WixToolset.Extensibility; 7 using WixToolset.Extensibility;
7 8
8 internal class InscribeContext : IInscribeContext 9 internal class InscribeContext : IInscribeContext
9 { 10 {
11 public InscribeContext(IServiceProvider serviceProvider)
12 {
13 this.ServiceProvider = serviceProvider;
14 }
15
16 public IServiceProvider ServiceProvider { get; }
17
10 public Messaging Messaging { get; } = Messaging.Instance; 18 public Messaging Messaging { get; } = Messaging.Instance;
11 19
12 public string IntermediateFolder { get; set; } 20 public string IntermediateFolder { get; set; }
diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs
new file mode 100644
index 00000000..c073c32b
--- /dev/null
+++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs
@@ -0,0 +1,47 @@
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.Core
4{
5 using System;
6 using WixToolset.Extensibility;
7 using WixToolset.Extensibility.Services;
8
9 public class WixToolsetServiceProvider : IServiceProvider
10 {
11 private ExtensionManager extensionManager;
12
13 public object GetService(Type serviceType)
14 {
15 if (serviceType == null) throw new ArgumentNullException(nameof(serviceType));
16
17 // Transients.
18 if (serviceType == typeof(IBindContext))
19 {
20 return new BindContext(this);
21 }
22
23 if (serviceType == typeof(IInscribeContext))
24 {
25 return new InscribeContext(this);
26 }
27
28 if (serviceType == typeof(ICommandLineContext))
29 {
30 return new CommandLineContext(this);
31 }
32
33 if (serviceType == typeof(ICommandLine))
34 {
35 return new CommandLine();
36 }
37
38 // Singletons.
39 if (serviceType == typeof(IExtensionManager))
40 {
41 return extensionManager = extensionManager ?? new ExtensionManager();
42 }
43
44 throw new ArgumentException($"Unknown service type: {serviceType.Name}", nameof(serviceType));
45 }
46 }
47}
diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs b/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs
index bc2786e9..daa3da42 100644
--- a/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs
+++ b/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs
@@ -20,7 +20,7 @@ namespace WixToolsetTest.CoreIntegrationFixture
20 var intermediateFolder = fs.GetFolder(); 20 var intermediateFolder = fs.GetFolder();
21 21
22 var program = new Program(); 22 var program = new Program();
23 var result = program.Run(new[] { "build", "Package.wxs", "PackageComponents.wxs", "-loc", "Package.en-us.wxl", "-bindpath", "data", "-intermediateFolder", intermediateFolder, "-o", $@"{intermediateFolder}\bin\test.msi" }); 23 var result = program.Run(new WixToolsetServiceProvider(), new[] { "build", "Package.wxs", "PackageComponents.wxs", "-loc", "Package.en-us.wxl", "-bindpath", "data", "-intermediateFolder", intermediateFolder, "-o", $@"{intermediateFolder}\bin\test.msi" });
24 24
25 Assert.Equal(0, result); 25 Assert.Equal(0, result);
26 Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msi"))); 26 Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msi")));
diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj b/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj
index 86482a19..bce6e6b2 100644
--- a/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj
+++ b/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj
@@ -12,25 +12,14 @@
12 </PropertyGroup> 12 </PropertyGroup>
13 13
14 <ItemGroup> 14 <ItemGroup>
15 <None Remove="TestData\SingleFile\data\test.txt" /> 15 <Content Include="TestData\SingleFile\data\test.txt" CopyToOutputDirectory="PreserveNewest" />
16 <None Remove="TestData\SingleFile\Package.en-us.wxl" /> 16 <Content Include="TestData\SingleFile\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" />
17 <None Remove="TestData\SingleFile\Package.wxs" /> 17 <Content Include="TestData\SingleFile\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
18 <None Remove="TestData\SingleFile\PackageComponents.wxs" /> 18 <Content Include="TestData\SingleFile\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" />
19 </ItemGroup> 19 </ItemGroup>
20 20
21 <ItemGroup> 21 <ItemGroup>
22 <Content Include="TestData\SingleFile\data\test.txt"> 22 <ProjectReference Include="..\..\wix\wix.csproj" />
23 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24 </Content>
25 <Content Include="TestData\SingleFile\Package.en-us.wxl">
26 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27 </Content>
28 <Content Include="TestData\SingleFile\Package.wxs">
29 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30 </Content>
31 <Content Include="TestData\SingleFile\PackageComponents.wxs">
32 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33 </Content>
34 </ItemGroup> 23 </ItemGroup>
35 24
36 <ItemGroup> 25 <ItemGroup>
@@ -38,8 +27,4 @@
38 <PackageReference Include="xunit" Version="2.2.0" /> 27 <PackageReference Include="xunit" Version="2.2.0" />
39 <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> 28 <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
40 </ItemGroup> 29 </ItemGroup>
41
42 <ItemGroup>
43 <ProjectReference Include="..\..\wix\wix.csproj" />
44 </ItemGroup>
45</Project> 30</Project>
diff --git a/src/wix/Program.cs b/src/wix/Program.cs
index 03b11c78..bebd80d5 100644
--- a/src/wix/Program.cs
+++ b/src/wix/Program.cs
@@ -4,6 +4,7 @@ namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using WixToolset.Data; 6 using WixToolset.Data;
7 using WixToolset.Extensibility.Services;
7 8
8 /// <summary> 9 /// <summary>
9 /// Wix Toolset Command-Line Interface. 10 /// Wix Toolset Command-Line Interface.
@@ -21,16 +22,41 @@ namespace WixToolset.Core
21 Messaging.Instance.InitializeAppName("WIX", "wix.exe"); 22 Messaging.Instance.InitializeAppName("WIX", "wix.exe");
22 Messaging.Instance.Display += DisplayMessage; 23 Messaging.Instance.Display += DisplayMessage;
23 24
25 var serviceProvider = new WixToolsetServiceProvider();
24 var program = new Program(); 26 var program = new Program();
25 return program.Run(args); 27 return program.Run(serviceProvider, args);
26 } 28 }
27 29
28 public int Run(string[] args) 30 /// <summary>
31 /// Executes the wix command-line interface.
32 /// </summary>
33 /// <param name="serviceProvider">Service provider to use throughout this execution.</param>
34 /// <param name="args">Command-line arguments to execute.</param>
35 /// <returns>Returns the application error code.</returns>
36 public int Run(IServiceProvider serviceProvider, string[] args)
29 { 37 {
30 var command = CommandLine.ParseStandardCommandLine(args); 38 var context = serviceProvider.GetService<ICommandLineContext>();
39 context.Messaging = Messaging.Instance;
40 context.ExtensionManager = CreateExtensionManagerWithStandardBackends(serviceProvider);
41 context.ParsedArguments = args;
42
43 var commandLine = serviceProvider.GetService<ICommandLine>();
44 var command = commandLine.ParseStandardCommandLine(context);
31 return command?.Execute() ?? 1; 45 return command?.Execute() ?? 1;
32 } 46 }
33 47
48 private static IExtensionManager CreateExtensionManagerWithStandardBackends(IServiceProvider serviceProvider)
49 {
50 var extensionManager = serviceProvider.GetService<IExtensionManager>();
51
52 foreach (var type in new[] { typeof(WixToolset.Core.Burn.StandardBackend), typeof(WixToolset.Core.WindowsInstaller.StandardBackend) })
53 {
54 extensionManager.Add(type.Assembly);
55 }
56
57 return extensionManager;
58 }
59
34 private static void DisplayMessage(object sender, DisplayEventArgs e) 60 private static void DisplayMessage(object sender, DisplayEventArgs e)
35 { 61 {
36 switch (e.Level) 62 switch (e.Level)