diff options
author | Rob Mensching <rob@firegiant.com> | 2022-07-26 17:20:39 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-08-01 20:25:19 -0700 |
commit | a627ca9b720047e633a8fe72003ab9bee31006c5 (patch) | |
tree | 2bc8a924bb4141ab718e74d08f6459a0ffe8d573 /src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs | |
parent | 521eb3c9cf38823a2c4019abb85dc0b3200b92cb (diff) | |
download | wix-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/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs')
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs b/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs new file mode 100644 index 00000000..32680e5d --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs | |||
@@ -0,0 +1,108 @@ | |||
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 WixToolsetTest.Sdk | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Linq; | ||
9 | using WixBuildTools.TestSupport; | ||
10 | |||
11 | public enum BuildSystem | ||
12 | { | ||
13 | DotNetCoreSdk, | ||
14 | MSBuild, | ||
15 | MSBuild64, | ||
16 | } | ||
17 | |||
18 | public static class MsbuildUtilities | ||
19 | { | ||
20 | public static MsbuildRunnerResult BuildProject(BuildSystem buildSystem, string projectPath, string[] arguments = null, string configuration = "Release", bool? outOfProc = null, string verbosityLevel = "normal", bool suppressValidation = true) | ||
21 | { | ||
22 | var allArgs = new List<string> | ||
23 | { | ||
24 | $"-verbosity:{verbosityLevel}", | ||
25 | $"-p:Configuration={configuration}", | ||
26 | $"-p:SuppressValidation={suppressValidation}", | ||
27 | // Node reuse means that child msbuild processes can stay around after the build completes. | ||
28 | // Under that scenario, the root msbuild does not reliably close its streams which causes us to hang. | ||
29 | "-nr:false", | ||
30 | $"-bl:{Path.ChangeExtension(projectPath, ".binlog")}" | ||
31 | }; | ||
32 | |||
33 | if (outOfProc.HasValue) | ||
34 | { | ||
35 | allArgs.Add($"-p:RunWixToolsOutOfProc={outOfProc.Value}"); | ||
36 | } | ||
37 | |||
38 | if (arguments != null) | ||
39 | { | ||
40 | allArgs.AddRange(arguments); | ||
41 | } | ||
42 | |||
43 | switch (buildSystem) | ||
44 | { | ||
45 | case BuildSystem.DotNetCoreSdk: | ||
46 | { | ||
47 | allArgs.Add(projectPath); | ||
48 | var result = DotnetRunner.Execute("msbuild", allArgs.ToArray()); | ||
49 | return new MsbuildRunnerResult | ||
50 | { | ||
51 | ExitCode = result.ExitCode, | ||
52 | Output = result.StandardOutput, | ||
53 | }; | ||
54 | } | ||
55 | case BuildSystem.MSBuild: | ||
56 | case BuildSystem.MSBuild64: | ||
57 | { | ||
58 | return MsbuildRunner.Execute(projectPath, allArgs.ToArray(), buildSystem == BuildSystem.MSBuild64); | ||
59 | } | ||
60 | default: | ||
61 | { | ||
62 | throw new NotImplementedException(); | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public static string GetQuotedPropertySwitch(BuildSystem buildSystem, string propertyName, string valueToQuote) | ||
68 | { | ||
69 | switch (buildSystem) | ||
70 | { | ||
71 | case BuildSystem.DotNetCoreSdk: | ||
72 | { | ||
73 | // If the value ends with a backslash, double-escape it (it should end up with four backslashes). | ||
74 | if (valueToQuote?.EndsWith("\\") == true) | ||
75 | { | ||
76 | valueToQuote += @"\\\"; | ||
77 | } | ||
78 | |||
79 | return $"-p:{propertyName}=\\\"{valueToQuote}\\\""; | ||
80 | } | ||
81 | case BuildSystem.MSBuild: | ||
82 | case BuildSystem.MSBuild64: | ||
83 | { | ||
84 | // If the value ends with a backslash, escape it. | ||
85 | if (valueToQuote?.EndsWith("\\") == true) | ||
86 | { | ||
87 | valueToQuote += @"\"; | ||
88 | } | ||
89 | |||
90 | return $"-p:{propertyName}=\"{valueToQuote}\""; | ||
91 | } | ||
92 | default: | ||
93 | { | ||
94 | throw new NotImplementedException(); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public static IEnumerable<string> GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem, bool? outOfProc = null) | ||
100 | { | ||
101 | var expectedOutOfProc = buildSystem == BuildSystem.DotNetCoreSdk || outOfProc.HasValue && outOfProc.Value; | ||
102 | var expectedToolExe = !expectedOutOfProc ? $"({toolName}.exe)" : | ||
103 | buildSystem == BuildSystem.DotNetCoreSdk ? $"{toolName}.dll\"" : $"{toolName}.exe"; | ||
104 | var expectedToolCommand = $"{expectedToolExe} {operation}"; | ||
105 | return result.Output.Where(line => line.Contains(expectedToolCommand)); | ||
106 | } | ||
107 | } | ||
108 | } | ||