diff options
author | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:37:18 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:37:18 -0700 |
commit | 985b2683b2717c83a27295b36e09b126083238f9 (patch) | |
tree | 622804d279e0ac58366dee62888e6a317a2b9d41 /src/internal/WixBuildTools.TestSupport/DotnetRunner.cs | |
parent | 3f583916719eeef598d10a5d4e14ef14f008243b (diff) | |
parent | 6a24996a2e831cfe402398af65b31fb1ecd575a9 (diff) | |
download | wix-985b2683b2717c83a27295b36e09b126083238f9.tar.gz wix-985b2683b2717c83a27295b36e09b126083238f9.tar.bz2 wix-985b2683b2717c83a27295b36e09b126083238f9.zip |
Merge WixBuildTools
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport/DotnetRunner.cs')
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/DotnetRunner.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/DotnetRunner.cs b/src/internal/WixBuildTools.TestSupport/DotnetRunner.cs new file mode 100644 index 00000000..82391178 --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport/DotnetRunner.cs | |||
@@ -0,0 +1,57 @@ | |||
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 WixBuildTools.TestSupport | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | |||
9 | public class DotnetRunner : ExternalExecutable | ||
10 | { | ||
11 | private static readonly object InitLock = new object(); | ||
12 | private static bool Initialized; | ||
13 | private static DotnetRunner Instance; | ||
14 | |||
15 | public static ExternalExecutableResult Execute(string command, string[] arguments = null) => | ||
16 | InitAndExecute(command, arguments); | ||
17 | |||
18 | private static ExternalExecutableResult InitAndExecute(string command, string[] arguments) | ||
19 | { | ||
20 | lock (InitLock) | ||
21 | { | ||
22 | if (!Initialized) | ||
23 | { | ||
24 | Initialized = true; | ||
25 | var dotnetPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH"); | ||
26 | if (String.IsNullOrEmpty(dotnetPath) || !File.Exists(dotnetPath)) | ||
27 | { | ||
28 | dotnetPath = "dotnet"; | ||
29 | } | ||
30 | |||
31 | Instance = new DotnetRunner(dotnetPath); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | return Instance.ExecuteCore(command, arguments); | ||
36 | } | ||
37 | |||
38 | private DotnetRunner(string exePath) : base(exePath) { } | ||
39 | |||
40 | private ExternalExecutableResult ExecuteCore(string command, string[] arguments) | ||
41 | { | ||
42 | var total = new List<string> | ||
43 | { | ||
44 | command, | ||
45 | }; | ||
46 | |||
47 | if (arguments != null) | ||
48 | { | ||
49 | total.AddRange(arguments); | ||
50 | } | ||
51 | |||
52 | var args = CombineArguments(total); | ||
53 | var mergeErrorIntoOutput = true; | ||
54 | return this.Run(args, mergeErrorIntoOutput); | ||
55 | } | ||
56 | } | ||
57 | } | ||