Skip to content

Commit

Permalink
WiX v5 uses wixext5 NuGet package subdirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnson committed Feb 18, 2024
1 parent 4f1209d commit afe9b12
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ext/WixExt.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<Content Include="$(MSBuildProjectName).targets" PackagePath="build" />
<Content Include="$(TargetPath)" PackagePath="wixext4" />
<Content Include="$(TargetPath)" PackagePath="wixext5" />

<PackageReference Include="WixToolset.Extensibility" PrivateAssets="all" />
</ItemGroup>
Expand Down
15 changes: 12 additions & 3 deletions src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ internal class ExtensionCacheManager
{
private IReadOnlyCollection<IExtensionCacheLocation> cacheLocations;

public ExtensionCacheManager(IMessaging messaging, IExtensionManager extensionManager)
public ExtensionCacheManager(IMessaging messaging, IExtensionManager extensionManager, IWixBranding branding)
{
this.Messaging = messaging;
this.ExtensionManager = extensionManager;
this.WixVersion = branding.ReplacePlaceholders("[FileVersionMajorMinor]");
}

private IMessaging Messaging { get; }

private IExtensionManager ExtensionManager { get; }

public string WixVersion { get; }

public async Task<bool> AddAsync(bool global, string extension, CancellationToken cancellationToken)
{
if (String.IsNullOrEmpty(extension))
Expand Down Expand Up @@ -212,11 +215,16 @@ private async Task<bool> 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);
}

Expand Down Expand Up @@ -266,6 +274,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public ExtensionCacheManagerCommand(IServiceProvider serviceProvider)
{
this.Messaging = serviceProvider.GetService<IMessaging>();
this.ExtensionManager = serviceProvider.GetService<IExtensionManager>();
this.WixBranding = serviceProvider.GetService<IWixBranding>();
this.ExtensionReferences = new List<string>();
}

private IMessaging Messaging { get; }

private IExtensionManager ExtensionManager { get; }

public IWixBranding WixBranding { get; }

private bool Global { get; set; }

private CacheSubcommand? Subcommand { get; set; }
Expand Down Expand Up @@ -68,7 +71,7 @@ public override async Task<int> ExecuteAsync(CancellationToken cancellationToken
}

var success = false;
var cacheManager = new ExtensionCacheManager(this.Messaging, this.ExtensionManager);
var cacheManager = new ExtensionCacheManager(this.Messaging, this.ExtensionManager, this.WixBranding);

switch (this.Subcommand)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ private static ExtensionCacheManager CreateExtensionCacheManager(IWixToolsetCore
{
var messaging = coreProvider.GetService<IMessaging>();
var extensionManager = coreProvider.GetService<IExtensionManager>();
var wixBranding = coreProvider.GetService<IWixBranding>();

var extensionCacheManager = new ExtensionCacheManager(messaging, extensionManager);
var extensionCacheManager = new ExtensionCacheManager(messaging, extensionManager, wixBranding);
singletons.Add(typeof(ExtensionCacheManager), extensionCacheManager);

return extensionCacheManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/wix/WixToolset.Sdk/tools/wix.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<WixToolsetPatchVersion>$$WixToolsetPatchVersion$$</WixToolsetPatchVersion>
<WixToolsetMajorMinorVersion>$$WixToolsetMajorMinorVersion$$</WixToolsetMajorMinorVersion>
<WixToolsetVersion>$$WixToolsetVersion$$</WixToolsetVersion>
<WixToolsetExtensionPackageFolder>wixext4</WixToolsetExtensionPackageFolder>
<WixToolsetExtensionPackageFolder>wixext5</WixToolsetExtensionPackageFolder>
</PropertyGroup>

<ImportGroup>
Expand Down
39 changes: 36 additions & 3 deletions src/wix/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand All @@ -304,7 +306,7 @@ public void CanManipulateExtensionCache()

var result = WixRunner.Execute(new[]
{
"extension", "add", "WixToolset.UI.wixext"
"extension", "add", "WixToolset.UI.wixext",
});

result.AssertSuccess();
Expand All @@ -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[]
Expand All @@ -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);
Expand Down

0 comments on commit afe9b12

Please sign in to comment.