Skip to content

Commit

Permalink
Wix4:
Browse files Browse the repository at this point in the history
- Issue #1557: Error when specifying Package Platform as ARM64
  • Loading branch information
oleg-shilo committed Jun 21, 2024
1 parent 9477fd5 commit 8986587
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
29 changes: 14 additions & 15 deletions Source/src/WixSharp/AutoElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ static XElement CreateComponentFor(this XDocument doc, XElement xDir)
}

private static string[] UserProfileFolders = new[]
{
"ProgramMenuFolder",
"AppDataFolder",
"LocalAppDataFolder",
"TempFolder",
"PersonalFolder",
"DesktopFolder",
"StartupFolder"
};
{
"ProgramMenuFolder",
"AppDataFolder",
"LocalAppDataFolder",
"TempFolder",
"PersonalFolder",
"DesktopFolder",
"StartupFolder"
};

static bool InUserProfile(this XElement xDir)
{
Expand Down Expand Up @@ -449,16 +449,12 @@ select s.Attribute("Icon").Value).Distinct())

static void InjectPlatformAttributes(XDocument doc)
{
var is64BitPlatform = doc.Root.Select("Package").HasAttribute("Platform", val => val == "x64");
var is64BitPlatform = doc.Root.Select("Package").HasAttribute("Platform", val => val.EndsWith("64"));

if (is64BitPlatform)
{
var platform = doc.Root.Select("Package").Attribute("Platform");
platform.Remove();
// doc says Component.Bitness may have value `default` that means "will be
// installed using the same bitness as the package".But package element does not have `bitness`.

// doc.Root.Select("Package").SetAttribute("Bitness", "always64");
// installed using the same bitness as the package. But package element does not have `bitness`.

doc.Descendants("Component")
.ForEach(comp =>
Expand All @@ -467,6 +463,9 @@ static void InjectPlatformAttributes(XDocument doc)
comp.SetAttributeValue("Bitness", "always64");
});
}

var platform = doc.Root.Select("Package").Attribute("Platform");
platform?.Remove();
}

internal static void ExpandCustomAttributes(XDocument doc, WixProject project)
Expand Down
5 changes: 5 additions & 0 deletions Source/src/WixSharp/Bootstrapper/Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ public XContainer[] ToXml()
/// </example>
public Variable[] Variables = new Variable[0];

/// <summary>
/// The target platform type.
/// </summary>
public Platform? Platform;

/// <summary>
/// Builds WiX Bootstrapper application from the specified <see cref="Bundle" /> project instance.
/// </summary>
Expand Down
22 changes: 12 additions & 10 deletions Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ THE SOFTWARE.
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using WixSharp.Bootstrapper;
using WixSharp.CommonTasks;
using WixToolset.Dtf.WindowsInstaller;
using IO = System.IO;
Expand Down Expand Up @@ -707,16 +708,17 @@ static string GenerateWixCommand(WixProject project, string wxsFile)
var candleCmdLineParams = new StringBuilder();
candleCmdLineParams.AppendFormat("{0} {1} {2} {3} \"{4}\" ", candleOptions, localization, extensionDlls, libFiles, wxsFile);

var msiProj = project as Project;
if (msiProj != null && msiProj.Platform != Platform.x86) // non-default architecture
candleCmdLineParams.Append($" -arch {Platform.x64}");
var platform = (project as Project)?.Platform ?? (project as Bundle)?.Platform;

if (platform.HasValue) // non-default architecture
candleCmdLineParams.Append($" -arch {platform}");

if (extraWxsFiles.IsNotEmpty())
candleCmdLineParams.Append(extraWxsFiles);

var buildCmd = candleCmdLineParams.ToString().ExpandEnvVars();

buildCmd = project.WixBuildCommandGenerated?.Invoke(buildCmd) ?? buildCmd;
buildCmd = project.OnWixBuildCommandGenerated(buildCmd);

return buildCmd;
}
Expand Down Expand Up @@ -2153,7 +2155,7 @@ static void ProcessDirectories(Project wProject, Dictionary<Feature, List<string
{
dummyDir = @"%ProgramFiles%\WixSharp\DummyDir";

if (wProject.Platform == Platform.x64)
if (wProject.Is64Bit)
dummyDir = dummyDir.Map64Dirs();

wProject.Dirs = new[] { new Dir(dummyDir) };
Expand Down Expand Up @@ -2263,14 +2265,14 @@ static void ProcessRegKeys(Project wProject, Dictionary<Feature, List<string>> f
{
if (regVal.Win64.HasValue)
{
if (regVal.IsWin64 && wProject.Platform == Platform.x86)
if (regVal.IsWin64 && !wProject.Is64Bit)
regVal.AttributesDefinition += ";Component:Bitness=always64";
else if (!regVal.IsWin64 && wProject.Platform == Platform.x64)
else if (!regVal.IsWin64 && wProject.Is64Bit)
regVal.AttributesDefinition += ";Component:Bitness=always32";
}
else
{
if (wProject.Platform != Platform.x86)
if (wProject.Is64Bit)
regVal.AttributesDefinition += ";Component:Bitness=always64";
}
}
Expand Down Expand Up @@ -2299,7 +2301,7 @@ static void ProcessRegKeys(Project wProject, Dictionary<Feature, List<string>> f
// case belongs to a permanent dir but not to the user dir. It is still shocking to enclose an entity
// that is a system wide to the directory. But the containment is slightly better in this case.

bool is64 = regVal.Win64 ?? (wProject.Platform == Platform.x64);
bool is64 = regVal.Win64 ?? wProject.Is64Bit;

XElement topLevelDir = GetTopLevelPermanentDir(product, is64);

Expand Down Expand Up @@ -2584,7 +2586,7 @@ static void ProcessProperties(Project wProject, XElement product, Dictionary<Fea
else
{
// otherwise `default` - the same as package x64/x32
if (wProject.Platform == Platform.x64)
if (wProject.Is64Bit)
RegistrySearchElement.SetAttribute("Bitness", "always64");
else
RegistrySearchElement.SetAttribute("Bitness", rvProp.Win64 ? "always64" : "always32");
Expand Down
5 changes: 0 additions & 5 deletions Source/src/WixSharp/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ public enum Platform
/// </summary>
x86,

/// <summary>
/// Set this value to declare that the package is an ia64 package. This value requires that the InstallerVersion property be set to 200 or greater.
/// </summary>
ia64,

/// <summary>
/// Set this value to declare that the package is an x64 package. This value requires that the InstallerVersion property be set to 200 or greater.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions Source/src/WixSharp/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public Project(string name, params WixObject[] items)
/// Supported file formats can be configured by setting <see cref="SignAllFilesOptions.SupportedFileFormats"/>.
/// When set to <c>true</c>, all files will be signed.
/// <p>Note, the digital signing will be performed on the original files specified in the <see cref="WixSharp.Project"/>
/// initialization.</p>
/// initialization.</p>
/// </summary>
public bool SignAllFiles = false;

Expand All @@ -212,7 +212,7 @@ internal virtual void Preprocess()
actions.ForEach(a => a.RefAssemblies = refAsms);
}

if (WixSharp.Compiler.AutoGeneration.Map64InstallDirs && this.Platform.HasValue && this.Platform.Value == WixSharp.Platform.x64)
if (WixSharp.Compiler.AutoGeneration.Map64InstallDirs && this.Platform.HasValue && this.Is64Bit)
{
foreach (var dir in this.AllDirs)
{
Expand Down Expand Up @@ -266,6 +266,8 @@ internal virtual void Preprocess()
/// </summary>
public Platform? Platform;

internal bool Is64Bit => Platform == WixSharp.Platform.x64 || Platform == WixSharp.Platform.arm64;

/// <summary>
/// Schedules the FailWhenDeferred custom action for the current platform.
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions Source/src/WixSharp/RegistrySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ public RegistrySearch(RegistryHive root, string key, string name, RegistrySearch
/// <param name="context">The context.</param>
public void Process(ProcessingContext context)
{
var platform = (context.Project as Project)?.Platform;
if (this.Win64 == null && platform != null)
this.Win64 = platform == Platform.x64;
// var platform = (context.Project as Project)?.Platform;
var proj = (context.Project as Project);

if (this.Win64 == null && proj.Platform != null)
this.Win64 = proj.Is64Bit;

base.Process(context, "RegistrySearch")
.SetAttribute("Bitness", Win64.HasValue ? (Win64.Value ? "always64" : "always32") : null);
Expand Down
4 changes: 3 additions & 1 deletion Source/src/WixSharp/WixProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public string Language
/// Use this event if you want to modify the command before
/// it is executed by `wix.exe`.
/// </summary>
public WixBuildCommandGeneratedDlgt WixBuildCommandGenerated = x => x;
public event WixBuildCommandGeneratedDlgt WixBuildCommandGenerated = x => x;

internal string OnWixBuildCommandGenerated(string command) => WixBuildCommandGenerated?.Invoke(command) ?? command;

internal string SetVersionFromIdValue = "";

Expand Down

0 comments on commit 8986587

Please sign in to comment.