From 38fe36a2072b1abde87b52643e43a3d7ddf2a2f5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 23 Mar 2023 14:36:09 -0700 Subject: Always add space to to test folder to flush out such bugs --- .../DisposableFileSystem.cs | 3 +- .../WixInternal.TestSupport/ExternalExecutable.cs | 2 +- .../WixInternal.TestSupport/MsbuildUtilities.cs | 51 +++++++++++----------- .../WixToolsetTest.CoreIntegration/PatchFixture.cs | 2 +- src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/internal/WixInternal.TestSupport/DisposableFileSystem.cs b/src/internal/WixInternal.TestSupport/DisposableFileSystem.cs index b03bbaa4..edf1f803 100644 --- a/src/internal/WixInternal.TestSupport/DisposableFileSystem.cs +++ b/src/internal/WixInternal.TestSupport/DisposableFileSystem.cs @@ -35,7 +35,8 @@ namespace WixInternal.TestSupport public string GetFolder(bool create = false) { - var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + // Always return a path with a space in it. + var path = Path.Combine(Path.GetTempPath(), ".WIXTEST " + Path.GetRandomFileName()); if (create) { diff --git a/src/internal/WixInternal.TestSupport/ExternalExecutable.cs b/src/internal/WixInternal.TestSupport/ExternalExecutable.cs index e0345dfb..9effd843 100644 --- a/src/internal/WixInternal.TestSupport/ExternalExecutable.cs +++ b/src/internal/WixInternal.TestSupport/ExternalExecutable.cs @@ -195,7 +195,7 @@ namespace WixInternal.TestSupport sb.Append(' '); } - if (arg.IndexOf(' ') > -1) + if (arg.IndexOf(' ') > -1 && !arg.EndsWith("\"")) { sb.Append("\""); sb.Append(arg); diff --git a/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs b/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs index 5560f993..95b3e37b 100644 --- a/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs +++ b/src/internal/WixInternal.TestSupport/MsbuildUtilities.cs @@ -27,7 +27,7 @@ namespace WixToolsetTest.Sdk // 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")}" + MsbuildUtilities.GetQuotedSwitch(buildSystem, "bl", Path.ChangeExtension(projectPath, ".binlog")) }; if (arguments != null) @@ -59,36 +59,35 @@ namespace WixToolsetTest.Sdk } } - public static string GetQuotedPropertySwitch(BuildSystem buildSystem, string propertyName, string valueToQuote) + public static string GetQuotedSwitch(BuildSystem _, string switchName, string switchValue) { - switch (buildSystem) + // If the value ends with a backslash, escape it. + if (switchValue?.EndsWith("\\") == true) { - 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 += @"\\\"; - } + switchValue += @"\"; + } - 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 $"-{switchName}:\"{switchValue}\""; + } - return $"-p:{propertyName}=\"{valueToQuote}\""; - } - default: - { - throw new NotImplementedException(); - } + public static string GetQuotedPropertySwitch(BuildSystem buildSystem, string propertyName, string propertyValue) + { + // If the value ends with a backslash, escape it. + if (propertyValue?.EndsWith("\\") == true) + { + propertyValue += @"\"; } + + var quotedValue = "\"" + propertyValue + "\""; + + // If the value contains a semicolon then escape-quote it (wrap with the characters: \") to wrap the value + // instead of just quoting the value, otherwise dotnet.exe will not pass the value to MSBuild correctly. + if (buildSystem == BuildSystem.DotNetCoreSdk && propertyValue?.IndexOf(';') > -1) + { + quotedValue = "\\\"" + propertyValue + "\\\""; + } + + return $"-p:{propertyName}={quotedValue}"; } public static IEnumerable GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem) diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs index f850615e..c27356c8 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs @@ -572,7 +572,7 @@ namespace WixToolsetTest.CoreIntegration private static void CreateAdminImage(string msiPath, string targetDir) { - var args = $"/a {Path.ChangeExtension(msiPath, "msi")} TARGETDIR={targetDir} /qn"; + var args = $"/a \"{Path.ChangeExtension(msiPath, "msi")}\" TARGETDIR=\"{targetDir}\" /qn"; var proc = Process.Start("msiexec.exe", args); proc.WaitForExit(5000); diff --git a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs index 6cbd445c..85774bfd 100644 --- a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs +++ b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs @@ -332,7 +332,7 @@ namespace WixToolsetTest.Sdk var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath), - $"-p:PdbOutputDir={pdbFolder}", + MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "PdbOutputDir", pdbFolder), "-p:SuppressValidation=true" }); result.AssertSuccess(); -- cgit v1.2.3-55-g6feb