From 7df7ac7fc016b15c58b54c6131ea6d985c17f02d Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sat, 17 Feb 2024 18:38:50 -0500 Subject: [PATCH] WiX v5 uses `wixext5` NuGet package subdirectory. Fixes wixtoolset/issues#7709. --- src/ext/WixExt.props | 2 +- .../ExtensionCacheManager.cs | 14 ++++++- .../ExtensionCacheWarnings.cs | 6 +++ .../ExtensibilityServices/ExtensionManager.cs | 4 +- src/wix/WixToolset.Sdk/tools/wix.props | 2 +- .../ExtensionFixture.cs | 39 +++++++++++++++++-- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/ext/WixExt.props b/src/ext/WixExt.props index fecfdd781..19a962549 100644 --- a/src/ext/WixExt.props +++ b/src/ext/WixExt.props @@ -10,7 +10,7 @@ - + diff --git a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs index 7f5dc0ff3..28aeae93d 100644 --- a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs +++ b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs @@ -29,12 +29,16 @@ public ExtensionCacheManager(IMessaging messaging, IExtensionManager extensionMa { this.Messaging = messaging; this.ExtensionManager = extensionManager; + + this.WixVersion = typeof(ExtensionCacheManager).Assembly.GetName().Version.Major.ToString(); } private IMessaging Messaging { get; } private IExtensionManager ExtensionManager { get; } + public string WixVersion { get; } + public async Task AddAsync(bool global, string extension, CancellationToken cancellationToken) { if (String.IsNullOrEmpty(extension)) @@ -212,11 +216,16 @@ private async Task DownloadAndExtractAsync(bool global, string id, string { stream.Position = 0; - Directory.CreateDirectory(extensionFolder); - using (var archive = new PackageArchiveReader(stream)) { var files = archive.GetFiles(extensionPackageRootFolderName); + if (!files.Any()) + { + this.Messaging.Write(ExtensionCacheWarnings.MissingExtensionPackageRootFolder(id, nugetVersion.ToString(), extensionPackageRootFolderName, this.WixVersion)); + return false; + } + + Directory.CreateDirectory(extensionFolder); await archive.CopyFilesAsync(extensionFolder, files, this.ExtractProgress, logger, cancellationToken); } @@ -266,6 +275,7 @@ private bool ExtensionFileExists(string baseFolder, string extensionId, string e var extensionFolder = Path.Combine(baseFolder, extensionId, extensionVersion, packageRootFolderName); if (!Directory.Exists(extensionFolder)) { + this.Messaging.Write(ExtensionCacheWarnings.MissingExtensionPackageRootFolder(extensionId, extensionVersion, packageRootFolderName, this.WixVersion)); return false; } diff --git a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheWarnings.cs b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheWarnings.cs index ddcbfdea9..28db205b7 100644 --- a/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheWarnings.cs +++ b/src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheWarnings.cs @@ -11,6 +11,11 @@ public static Message NugetException(string extensionId, string exceptionMessage return Message(new SourceLineNumber(extensionId), Ids.NugetException, "{0}", exceptionMessage); } + public static Message MissingExtensionPackageRootFolder(string extensionId, string packageVersion, string packageRootFolderName, string wixVersion) + { + return Message(new SourceLineNumber(extensionId), Ids.MissingExtensionPackageRootFolder, "Could not find expected package root folder {0}. Ensure {1}/{2} is compatible with WiX v{3}.", packageRootFolderName, extensionId, packageVersion, wixVersion); + } + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) { return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, format, args); @@ -19,6 +24,7 @@ private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string public enum Ids { NugetException = 6100, + MissingExtensionPackageRootFolder = 6101, } // last available is 6499. 6500 is ExtensionCacheErrors. } } diff --git a/src/wix/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs b/src/wix/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs index 00ab5e6df..840b32d4f 100644 --- a/src/wix/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs +++ b/src/wix/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs @@ -15,8 +15,8 @@ namespace WixToolset.Core.ExtensibilityServices internal class ExtensionManager : IExtensionManager { - // This value needs to stay in sync with the Property in "wix.targets" with the same name. - private const string WixToolsetExtensionPackageFolder = "wixext4"; + // This value needs to stay in sync with the Property in "wix.props" with the same name. + private const string WixToolsetExtensionPackageFolder = "wixext5"; private const string UserWixFolderName = ".wix"; private const string MachineWixFolderName = "WixToolset"; diff --git a/src/wix/WixToolset.Sdk/tools/wix.props b/src/wix/WixToolset.Sdk/tools/wix.props index b867ca8ac..284b93b00 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.props +++ b/src/wix/WixToolset.Sdk/tools/wix.props @@ -9,7 +9,7 @@ $$WixToolsetPatchVersion$$ $$WixToolsetMajorMinorVersion$$ $$WixToolsetVersion$$ - wixext4 + wixext5 diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs index a59187b60..beb625b1d 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs @@ -12,6 +12,8 @@ namespace WixToolsetTest.CoreIntegration using WixToolset.Data; using WixToolset.Data.Symbols; using Xunit; + using System.Diagnostics; + using System.Reflection; public class ExtensionFixture { @@ -290,7 +292,7 @@ public void CannotBuildWithMissingVersionedExtension() } } - [Fact] + [Fact(Skip = "Depends on a v5 extension being available, which isn't true for nuget.org yet or this early in the build.")] public void CanManipulateExtensionCache() { var currentFolder = Environment.CurrentDirectory; @@ -304,7 +306,7 @@ public void CanManipulateExtensionCache() var result = WixRunner.Execute(new[] { - "extension", "add", "WixToolset.UI.wixext" + "extension", "add", "WixToolset.UI.wixext", }); result.AssertSuccess(); @@ -318,8 +320,12 @@ public void CanManipulateExtensionCache() }); result.AssertSuccess(); + var output = result.Messages.Select(m => m.ToString()).Single(); - Assert.StartsWith("WixToolset.UI.wixext 4.", output); + var executingAssembly = Assembly.GetExecutingAssembly(); + var fileVersion = FileVersionInfo.GetVersionInfo(executingAssembly.Location); + + Assert.StartsWith($"WixToolset.UI.wixext {fileVersion.FileMajorPart}", output); Assert.DoesNotContain("damaged", output); result = WixRunner.Execute(new[] @@ -337,6 +343,33 @@ public void CanManipulateExtensionCache() } } + [Fact] + public void TryingToAddAV4ExtensionFails() + { + var currentFolder = Environment.CurrentDirectory; + + try + { + using (var fs = new DisposableFileSystem()) + { + var folder = fs.GetFolder(true); + Environment.CurrentDirectory = folder; + + var result = WixRunner.Execute(new[] + { + "extension", "add", "WixToolset.UI.wixext/4.0.4", + }); + + Assert.Equal(2, result.ExitCode); + Assert.Equal(6101, result.Messages.Single().Id); + } + } + finally + { + Environment.CurrentDirectory = currentFolder; + } + } + private static void Build(string[] args) { var result = WixRunner.Execute(args);