diff options
| author | Rob Mensching <rob@firegiant.com> | 2022-11-08 14:58:05 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2022-11-08 16:20:25 -0800 |
| commit | c843b47d6233153fa961c6d0e61edf7cedf255bb (patch) | |
| tree | 9eae6badd42d3badb8665b7414b4d44ca48d6ae1 /src/internal/WixInternal.TestSupport/MsbuildUtilities.cs | |
| parent | 7e498d6348c26583972ea1cdf7d51dadc8f5b792 (diff) | |
| download | wix-c843b47d6233153fa961c6d0e61edf7cedf255bb.tar.gz wix-c843b47d6233153fa961c6d0e61edf7cedf255bb.tar.bz2 wix-c843b47d6233153fa961c6d0e61edf7cedf255bb.zip | |
Separate WixInternal content from official WixToolset namespace
Diffstat (limited to 'src/internal/WixInternal.TestSupport/MsbuildUtilities.cs')
| -rw-r--r-- | src/internal/WixInternal.TestSupport/MsbuildUtilities.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs b/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs new file mode 100644 index 00000000..5560f993 --- /dev/null +++ b/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs | |||
| @@ -0,0 +1,101 @@ | |||
| 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 WixInternal.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", 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 (arguments != null) | ||
| 34 | { | ||
| 35 | allArgs.AddRange(arguments); | ||
| 36 | } | ||
| 37 | |||
| 38 | switch (buildSystem) | ||
| 39 | { | ||
| 40 | case BuildSystem.DotNetCoreSdk: | ||
| 41 | { | ||
| 42 | allArgs.Add(projectPath); | ||
| 43 | var result = DotnetRunner.Execute("msbuild", allArgs.ToArray()); | ||
| 44 | return new MsbuildRunnerResult | ||
| 45 | { | ||
| 46 | ExitCode = result.ExitCode, | ||
| 47 | Output = result.StandardOutput, | ||
| 48 | }; | ||
| 49 | } | ||
| 50 | case BuildSystem.MSBuild: | ||
| 51 | case BuildSystem.MSBuild64: | ||
| 52 | { | ||
| 53 | return MsbuildRunner.Execute(projectPath, allArgs.ToArray(), buildSystem == BuildSystem.MSBuild64); | ||
| 54 | } | ||
| 55 | default: | ||
| 56 | { | ||
| 57 | throw new NotImplementedException(); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | public static string GetQuotedPropertySwitch(BuildSystem buildSystem, string propertyName, string valueToQuote) | ||
| 63 | { | ||
| 64 | switch (buildSystem) | ||
| 65 | { | ||
| 66 | case BuildSystem.DotNetCoreSdk: | ||
| 67 | { | ||
| 68 | // If the value ends with a backslash, double-escape it (it should end up with four backslashes). | ||
| 69 | if (valueToQuote?.EndsWith("\\") == true) | ||
| 70 | { | ||
| 71 | valueToQuote += @"\\\"; | ||
| 72 | } | ||
| 73 | |||
| 74 | return $"-p:{propertyName}=\\\"{valueToQuote}\\\""; | ||
| 75 | } | ||
| 76 | case BuildSystem.MSBuild: | ||
| 77 | case BuildSystem.MSBuild64: | ||
| 78 | { | ||
| 79 | // If the value ends with a backslash, escape it. | ||
| 80 | if (valueToQuote?.EndsWith("\\") == true) | ||
| 81 | { | ||
| 82 | valueToQuote += @"\"; | ||
| 83 | } | ||
| 84 | |||
| 85 | return $"-p:{propertyName}=\"{valueToQuote}\""; | ||
| 86 | } | ||
| 87 | default: | ||
| 88 | { | ||
| 89 | throw new NotImplementedException(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | public static IEnumerable<string> GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem) | ||
| 95 | { | ||
| 96 | var expectedToolExe = buildSystem == BuildSystem.DotNetCoreSdk ? $"{toolName}.dll\"" : $"{toolName}.exe"; | ||
| 97 | var expectedToolCommand = $"{expectedToolExe} {operation}"; | ||
| 98 | return result.Output.Where(line => line.Contains(expectedToolCommand)); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
