From 07b3d459ea0a45cbef29b98d283edafbab26462a Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 12 Oct 2022 22:01:55 -0700 Subject: Normalize ToolsetTask implementation to call wix.exe and heat.exe Share the ToolsetTask implementation that can find .NET Core and .NET Framework with multiple architectures. Fixes 6951 --- .../FileSearchHelperMethods.cs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs (limited to 'src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs') diff --git a/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs b/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs new file mode 100644 index 00000000..442fedd6 --- /dev/null +++ b/src/internal/WixToolset.BaseBuildTasks.Sources/FileSearchHelperMethods.cs @@ -0,0 +1,57 @@ +// 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 WixToolset.BaseBuildTasks +{ + using System; + using System.IO; + + /// + /// Contains helper methods on searching for files + /// + public static class FileSearchHelperMethods + { + /// + /// Searches for the existence of a file in multiple directories. + /// Search is satisfied if default file path is valid and exists. If not, + /// file name is extracted from default path and combined with each of the directories + /// looking to see if it exists. If not found, input default path is returned. + /// + /// Array of directories to look in, without filenames in them + /// Default path - to use if not found + /// File path if file found. Empty string if not found + public static string SearchFilePaths(string[] directories, string defaultFullPath) + { + if (String.IsNullOrEmpty(defaultFullPath)) + { + return String.Empty; + } + + if (File.Exists(defaultFullPath)) + { + return defaultFullPath; + } + + if (directories == null) + { + return String.Empty; + } + + var fileName = Path.GetFileName(defaultFullPath); + foreach (var currentPath in directories) + { + if (String.IsNullOrWhiteSpace(currentPath)) + { + continue; + } + + var path = Path.Combine(currentPath, fileName); + if (File.Exists(path)) + { + return path; + } + } + + return String.Empty; + } + } +} -- cgit v1.2.3-55-g6feb