From e6ef75f3616f1221a43e3b412b42f9ca6a2bef7e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 20 Nov 2022 14:59:57 -0800 Subject: Log error when path to executable cannot be found in MSBuild tool task This is additional logging to try to track down the root cause of 7035. --- .../BaseToolsetTask.cs | 47 ++++++++++++++++------ src/wix/WixToolset.BuildTasks/ReadTracking.cs | 2 +- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/internal/WixInternal.BaseBuildTasks.Sources/BaseToolsetTask.cs b/src/internal/WixInternal.BaseBuildTasks.Sources/BaseToolsetTask.cs index d9e3b5e8..6edd4a35 100644 --- a/src/internal/WixInternal.BaseBuildTasks.Sources/BaseToolsetTask.cs +++ b/src/internal/WixInternal.BaseBuildTasks.Sources/BaseToolsetTask.cs @@ -3,6 +3,7 @@ namespace WixToolset.BaseBuildTasks { using System; + using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using Microsoft.Build.Utilities; @@ -129,24 +130,48 @@ namespace WixToolset.BaseBuildTasks return false; } #else - private static string GetArchitectureFolder(string baseFolder) + private string FindArchitectureSpecificToolPath(string baseFolder) { + var checkedPaths = new List(); + // First try to find a folder that matches this task's architecture. - var folder = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); + var archFolder = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); + + var path = Path.Combine(baseFolder, archFolder, this.ToolExe); + + if (File.Exists(path)) + { + return path; + } + + checkedPaths.Add(path); - if (Directory.Exists(Path.Combine(baseFolder, folder))) + // Try to fallback to "x86" folder since it tends to run on all architectures. + if (!String.Equals(archFolder, "x86", StringComparison.OrdinalIgnoreCase)) { - return folder; + path = Path.Combine(baseFolder, "x86", this.ToolExe); + + if (File.Exists(path)) + { + return path; + } + + checkedPaths.Add(path); } - // Try to fallback to "x86" folder. - if (folder != "x86" && Directory.Exists(Path.Combine(baseFolder, "x86"))) + // Return empty, even though this isn't likely to be there. + path = Path.Combine(baseFolder, this.ToolExe); + + if (File.Exists(path)) { - return "x86"; + return path; } - // Return empty, even though this isn't likely to be useful. - return String.Empty; + checkedPaths.Add(path); + + this.Log.LogError("Cannot find tool executable {0} at any of the checked paths: {1}. This is unexpected and will cause later commands to fail.", this.ToolExe, String.Join(", ", checkedPaths)); + + return path; } #endif @@ -159,9 +184,7 @@ namespace WixToolset.BaseBuildTasks #else var thisTaskFolder = Path.GetDirectoryName(new Uri(typeof(BaseToolsetTask).Assembly.CodeBase).AbsolutePath); - var archFolder = GetArchitectureFolder(thisTaskFolder); - - return Path.Combine(thisTaskFolder, archFolder, this.ToolExe); + return this.FindArchitectureSpecificToolPath(thisTaskFolder); #endif } diff --git a/src/wix/WixToolset.BuildTasks/ReadTracking.cs b/src/wix/WixToolset.BuildTasks/ReadTracking.cs index f92baaf1..25215956 100644 --- a/src/wix/WixToolset.BuildTasks/ReadTracking.cs +++ b/src/wix/WixToolset.BuildTasks/ReadTracking.cs @@ -93,7 +93,7 @@ namespace WixToolset.BuildTasks } else { - this.Log.LogError($"Failed to parse tracked line: {line}"); + this.Log.LogError("Failed to parse tracked line: {0}", line); } } } -- cgit v1.2.3-55-g6feb