diff --git a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs index 28aeae93d..cf40b2825 100644 --- a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs +++ b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs @@ -83,51 +83,54 @@ public Task> ListAsync(bool global, string extensio (var extensionId, var extensionVersion) = ParseExtensionReference(extension); - var cacheFolder = this.GetCacheFolder(global); - - var searchFolder = Path.Combine(cacheFolder, extensionId, extensionVersion); + var cacheFolders = this.GetCacheFolders(global); - if (!Directory.Exists(searchFolder)) - { - } - else if (!String.IsNullOrEmpty(extensionVersion)) // looking for an explicit version of an extension. + foreach (var cacheFolder in cacheFolders) { - var present = this.ExtensionFileExists(cacheFolder, extensionId, extensionVersion); - found.Add(new CachedExtension(extensionId, extensionVersion, !present)); - } - else // looking for all versions of an extension or all versions of all extensions. - { - IEnumerable foundExtensionIds; + var searchFolder = Path.Combine(cacheFolder, extensionId, extensionVersion); - if (String.IsNullOrEmpty(extensionId)) + if (!Directory.Exists(searchFolder)) { - // Looking for all versions of all extensions. - foundExtensionIds = Directory.GetDirectories(cacheFolder).Select(folder => Path.GetFileName(folder)).ToList(); } - else + else if (!String.IsNullOrEmpty(extensionVersion)) // looking for an explicit version of an extension. { - // Looking for all versions of a single extension. - var extensionFolder = Path.Combine(cacheFolder, extensionId); - foundExtensionIds = Directory.Exists(extensionFolder) ? new[] { extensionId } : Array.Empty(); + var present = this.ExtensionFileExists(cacheFolder, extensionId, extensionVersion); + found.Add(new CachedExtension(extensionId, extensionVersion, !present)); } - - foreach (var foundExtensionId in foundExtensionIds) + else // looking for all versions of an extension or all versions of all extensions. { - var extensionFolder = Path.Combine(cacheFolder, foundExtensionId); + IEnumerable foundExtensionIds; - foreach (var folder in Directory.GetDirectories(extensionFolder)) + if (String.IsNullOrEmpty(extensionId)) + { + // Looking for all versions of all extensions. + foundExtensionIds = Directory.GetDirectories(cacheFolder).Select(folder => Path.GetFileName(folder)).ToList(); + } + else { - cancellationToken.ThrowIfCancellationRequested(); + // Looking for all versions of a single extension. + var extensionFolder = Path.Combine(cacheFolder, extensionId); + foundExtensionIds = Directory.Exists(extensionFolder) ? new[] { extensionId } : Array.Empty(); + } - var foundExtensionVersion = Path.GetFileName(folder); + foreach (var foundExtensionId in foundExtensionIds) + { + var extensionFolder = Path.Combine(cacheFolder, foundExtensionId); - if (!NuGetVersion.TryParse(foundExtensionVersion, out _)) + foreach (var foundExtensionVersionFolder in Directory.GetDirectories(extensionFolder)) { - continue; - } + cancellationToken.ThrowIfCancellationRequested(); + + var foundExtensionVersion = Path.GetFileName(foundExtensionVersionFolder); - var present = this.ExtensionFileExists(cacheFolder, foundExtensionId, foundExtensionVersion); - found.Add(new CachedExtension(foundExtensionId, foundExtensionVersion, !present)); + if (!NuGetVersion.TryParse(foundExtensionVersion, out _)) + { + continue; + } + + var present = this.ExtensionFileExists(cacheFolder, foundExtensionId, foundExtensionVersion); + found.Add(new CachedExtension(foundExtensionId, foundExtensionVersion, !present)); + } } } } @@ -149,6 +152,18 @@ private string GetCacheFolder(bool global) return cacheLocation.Path; } + private IEnumerable GetCacheFolders(bool global) + { + if (this.cacheLocations == null) + { + this.cacheLocations = this.ExtensionManager.GetCacheLocations(); + } + + var cacheLocations = this.cacheLocations.Where(l => global || l.Scope == ExtensionCacheLocationScope.Project).OrderBy(l => l.Scope).Select(l => l.Path); + + return cacheLocations; + } + private async Task DownloadAndExtractAsync(bool global, string id, string version, CancellationToken cancellationToken) { var logger = NullLogger.Instance;