Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiX v5 uses wixext5 NuGet package subdirectory. #495

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 12 additions & 2 deletions src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> AddAsync(bool global, string extension, CancellationToken cancellationToken)
{
if (String.IsNullOrEmpty(extension))
Expand Down Expand Up @@ -212,11 +216,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 +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;
}

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 @@ -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
Loading