From a627ca9b720047e633a8fe72003ab9bee31006c5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 26 Jul 2022 17:20:39 -0700 Subject: 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 --- .../WixBuildTools.TestSupport/MsbuildUtilities.cs | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs (limited to 'src/internal/WixBuildTools.TestSupport') 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 @@ +// 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. + +namespace WixToolsetTest.Sdk +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using WixBuildTools.TestSupport; + + public enum BuildSystem + { + DotNetCoreSdk, + MSBuild, + MSBuild64, + } + + public static class MsbuildUtilities + { + public static MsbuildRunnerResult BuildProject(BuildSystem buildSystem, string projectPath, string[] arguments = null, string configuration = "Release", bool? outOfProc = null, string verbosityLevel = "normal", bool suppressValidation = true) + { + var allArgs = new List + { + $"-verbosity:{verbosityLevel}", + $"-p:Configuration={configuration}", + $"-p:SuppressValidation={suppressValidation}", + // Node reuse means that child msbuild processes can stay around after the build completes. + // Under that scenario, the root msbuild does not reliably close its streams which causes us to hang. + "-nr:false", + $"-bl:{Path.ChangeExtension(projectPath, ".binlog")}" + }; + + if (outOfProc.HasValue) + { + allArgs.Add($"-p:RunWixToolsOutOfProc={outOfProc.Value}"); + } + + if (arguments != null) + { + allArgs.AddRange(arguments); + } + + switch (buildSystem) + { + case BuildSystem.DotNetCoreSdk: + { + allArgs.Add(projectPath); + var result = DotnetRunner.Execute("msbuild", allArgs.ToArray()); + return new MsbuildRunnerResult + { + ExitCode = result.ExitCode, + Output = result.StandardOutput, + }; + } + case BuildSystem.MSBuild: + case BuildSystem.MSBuild64: + { + return MsbuildRunner.Execute(projectPath, allArgs.ToArray(), buildSystem == BuildSystem.MSBuild64); + } + default: + { + throw new NotImplementedException(); + } + } + } + + public static string GetQuotedPropertySwitch(BuildSystem buildSystem, string propertyName, string valueToQuote) + { + switch (buildSystem) + { + case BuildSystem.DotNetCoreSdk: + { + // If the value ends with a backslash, double-escape it (it should end up with four backslashes). + if (valueToQuote?.EndsWith("\\") == true) + { + valueToQuote += @"\\\"; + } + + return $"-p:{propertyName}=\\\"{valueToQuote}\\\""; + } + case BuildSystem.MSBuild: + case BuildSystem.MSBuild64: + { + // If the value ends with a backslash, escape it. + if (valueToQuote?.EndsWith("\\") == true) + { + valueToQuote += @"\"; + } + + return $"-p:{propertyName}=\"{valueToQuote}\""; + } + default: + { + throw new NotImplementedException(); + } + } + } + + public static IEnumerable GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem, bool? outOfProc = null) + { + var expectedOutOfProc = buildSystem == BuildSystem.DotNetCoreSdk || outOfProc.HasValue && outOfProc.Value; + var expectedToolExe = !expectedOutOfProc ? $"({toolName}.exe)" : + buildSystem == BuildSystem.DotNetCoreSdk ? $"{toolName}.dll\"" : $"{toolName}.exe"; + var expectedToolCommand = $"{expectedToolExe} {operation}"; + return result.Output.Where(line => line.Contains(expectedToolCommand)); + } + } +} -- cgit v1.2.3-55-g6feb