From 94886929a56c2964efdfc70c19f6948aad3bed78 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Tue, 9 Jul 2024 09:28:51 +0100 Subject: [PATCH] Normalize path separators in-place --- .../PackageConfigurationUpdater.cs | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Bonsai.Configuration/PackageConfigurationUpdater.cs b/Bonsai.Configuration/PackageConfigurationUpdater.cs index 52d7003a..db667a21 100644 --- a/Bonsai.Configuration/PackageConfigurationUpdater.cs +++ b/Bonsai.Configuration/PackageConfigurationUpdater.cs @@ -46,7 +46,7 @@ public class PackageConfigurationUpdater : IDisposable public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfiguration configuration, IPackageManager manager, string bootstrapperPath = null, PackageIdentity bootstrapperName = null) { packageManager = manager ?? throw new ArgumentNullException(nameof(manager)); - packageConfiguration = NormalizePathSeparators(configuration ?? throw new ArgumentNullException(nameof(configuration))); + packageConfiguration = configuration ?? throw new ArgumentNullException(nameof(configuration)); bootstrapperFramework = projectFramework ?? throw new ArgumentNullException(nameof(projectFramework)); bootstrapperExePath = bootstrapperPath ?? string.Empty; bootstrapperDirectory = Path.GetDirectoryName(bootstrapperExePath); @@ -58,6 +58,7 @@ public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfi var galleryPath = Path.Combine(bootstrapperDirectory, GalleryDirectory); var galleryPackageSource = new PackageSource(galleryPath); galleryRepository = new SourceRepository(galleryPackageSource, Repository.Provider.GetCoreV3()); + NormalizePathSeparators(packageConfiguration); } string GetRelativePath(string path) @@ -74,29 +75,21 @@ static string CombinePath(string path1, string path2) return PathUtility.GetPathWithForwardSlashes(Path.Combine(path1, path2)); } - static PackageConfiguration NormalizePathSeparators(PackageConfiguration configuration) + static void NormalizePathSeparators(PackageConfiguration configuration) { - var normalized = new PackageConfiguration(); - normalized.ConfigurationFile = configuration.ConfigurationFile; - normalized.Packages.AddRange(configuration.Packages); - normalized.AssemblyReferences.AddRange(configuration.AssemblyReferences); - foreach (var assemblyLocation in configuration.AssemblyLocations) { - normalized.AssemblyLocations.Add( - assemblyLocation.AssemblyName, - assemblyLocation.ProcessorArchitecture, - PathUtility.GetPathWithForwardSlashes(assemblyLocation.Location)); + assemblyLocation.Location = PathUtility.GetPathWithForwardSlashes(assemblyLocation.Location); } - foreach (var folder in configuration.LibraryFolders) + // cannot normalize in place since path is collection key + var libraryFolders = configuration.LibraryFolders.ToArray(); + configuration.LibraryFolders.Clear(); + foreach (var folder in libraryFolders) { - normalized.LibraryFolders.Add( - PathUtility.GetPathWithForwardSlashes(folder.Path), - folder.Platform); + folder.Path = PathUtility.GetPathWithForwardSlashes(folder.Path); + configuration.LibraryFolders.Add(folder); } - - return normalized; } static bool IsTaggedPackage(PackageReaderBase package)