oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.09k stars 172 forks source link

Error when specifying Package Platform as ARM64 #1557

Closed artlaskow closed 3 weeks ago

artlaskow commented 2 months ago

Package used: <PackageReference Include="WixSharp_wix4" Version="2.1.7" />.

I'm trying to create definition for installer that can be run only on ARM64 system. When specifying project.Platform = Platform.x64; installer builds correctly. If project.Platform = Platform.arm64; is specified, then following error appears:

Wix project file has been built: C:\MyProject\bin\x64\Debug\net472\MyProject.wxs

Compiling MyProject.wxs
Source base directory: C:\MyProject\bin\x64\Debug\net472
Wix version: 5.0.0
C:\MyProject\bin\x64\Debug\net472\MyProject.wxs(2) : error WIX0004: The Package element contains an unexpected attribute 'Platform'.

In this example the project is built for x64. I compiled it for ARM64 and ran it on ARM64 machine with the same result.

According to WiX documentation, Package element indeed doesn't contain Platform property https://wixtoolset.org/docs/schema/wxs/package/. I tried to follow the official sample for x64 to target ARM64, but it appears that additional configuration is needed.

What would be the correct way of creating installer for ARM64? I can specify more information if needed.

oleg-shilo commented 2 months ago

This is a difficult one.

WiX4 does not longer accept setting the target architecture of the msi package. Instead it requires setting the bitness attribute of the component and passing the 'magic' -arch switch to the wix.exe during the compilation. Why "magic"? Because wix.exe build -? is silent about the possible values

image

Thus I can only guess that it might be arm64. And indeed wix.exe tries to compile the msi. I just wanted you to be aware how much guessing I have to do as the documentation is not very helpful for this topic.

Anyway, we can solve this problem with a little manual intervention in the build process

This should build the msi.

Let me know if it builds correctly and I will integrate this process into the next release.

But just to assist you with our test I have built you pre-release packages (attached) that you can use if you do not want to fiddle with the batch file. With v2.1.9 you can manipulate the build command on-fly with the new WixBuildCommandGenerated event:

project.Platform = Platform.x64;
project.InstallerVersion = 500;
project.WixBuildCommandGenerated +=
    cmd => cmd.Replace("-arch x64", "-arch arm64");

WixSharp.zip

artlaskow commented 2 months ago

Alright, so I tested manual steps you you posted and I would like to report success, but with some minor adjustments to Bundle building. The msi I generate is later used to build a bundle. First off, bundle cmd file doesn't have arch parameter. No big deal, I added it to cmd file, but then I noticed a minor bug: -o parameter in Build_MyProject.cmd is set to Build_MyProject.cmd.exe, which seems to be an error, because I specify OutFileName as MyProject. Other than that everything works fine from what I tested so far.

Thanks a ton for your help, for looking into this so quickly and coming up with a temporary solution!

oleg-shilo commented 2 months ago

Excellent. Then it is the way to go. I will now implement arm support by automating all these manual steps.

added it to cmd file,

You can add it as

bootstrapper.WixOptions += " -arch  arm64";

Can you please confirm that the code above generates the correct bundle cmd.

And I will check the Build_MyProject.cmd.exe problem

artlaskow commented 2 months ago

Can you please confirm that the code above generates the correct bundle cmd.

Yes, it does. Extra spaces before and after -arch are redundant, but other than that cmd generates as it should.

I will now implement arm support by automating all these manual steps.

Thank you again!

talbotsk commented 2 months ago

Hi, I am facing the same problem, but with x86 architecture. Here you can find the allowed values for -arch switch: https://wixtoolset.org/docs/tools/wixexe/#build

Your first proposed solution works only for x64, not for other architectures, because other architectures add Platform attribute to Package element. I think the x86 architecture should be the default option according to wix specification.

The second solution worked for me too.

I tryied to install your WixSharp_wix4 2.1.9-pre, but it failed:

Restoring packages for C:\s\sln\proj\InstallerSetup\InstallerSetup.csproj...
  CACHE https://api.nuget.org/v3/vulnerabilities/index.json
  CACHE https://api.nuget.org/v3-vulnerabilities/2024.06.19.23.26.49/vulnerability.base.json
  CACHE https://api.nuget.org/v3-vulnerabilities/2024.06.19.23.26.49/2024.06.20.11.26.49/vulnerability.update.json
NU1102: Unable to find package WixSharp_wix4.bin with version (>= 2.1.9)
  - Found 1 version(s) in WixSharpLocal [ Nearest version: 2.1.9-pre ]

Anyway I think that setting project.Platform = Platform.x64; to other platform than x64 will add unwanted attribute Platform to Package element.

I tryied to add WixOptions += " -arch x86 ". It didn't work for me. It was overwritten by previously inserted "-arch x64" left in the command line from BuildMsi(), e.g.: "C:\Users\user\.dotnet\tools\wix.exe" build -sw1026 -sw1076 -sw1079 -sw1149 -arch x86 -ext "C:\Users\user\.wix\extensions\WixToolset.Util.wixext\4.0.5\wixext4\WixToolset.Util.wixext.dll" -ext "C:\Users\user\.wix\extensions\WixToolset.UI.wixext\4.0.5\wixext4\WixToolset.UI.wixext.dll" "C:\s\sln\proj\InstallerSetup\msi.wxs" -arch x64 -o "C:\s\sln\proj\InstallerSetup\msi.msi" I am using class ManagedProject.

Can you resolve this issue also for x86 architecture or even better for any type of architectures? Thank you very much!

Edit: Could you internally read Platform property of the project set by business logic, set -arch for wix.exe accordingly and reset it to null for further processing, let the Platform attribute of Project element is not set?

oleg-shilo commented 2 months ago

@artlaskow, great, thank you. I wish wix.exe was printing it on -help. I will try to implement it all on the weekend

@talbotsk, you cannot use WixOptions += " -arch x86 " as it is adding an extra arg but you need the replacement. The replacement mechanism for build cmd at this very moment is only available via building batch file or with the pre-release package attached (5 posts above).

Anyway, I am planning to do the release on weekend and I am going to add processing of the platform property as it was in WixSharp for wix3.

read Platform property of the project set by business logic,

yes it does it already I only need to add arm as we just discioverd that it still works but in a different way

talbotsk commented 2 months ago

@oleg-shilo does wixsharp\Source\src\WixSharp.Samples\Wix# Samples\External_UI\ConsoleSetup\Properties\Resources.resx missing in your repository wix-v4-master? I can't build: static string SetupDependencies() { byte[] msiData = ConsoleSetup.Properties.Resource.MyProduct_msi; There is an error: Severity Code Description Project File Line Suppression State Details Error (active) CS0234 The type or namespace name 'Resource' does not exist in the namespace 'ConsoleSetup.Properties' (are you missing an assembly reference?) ConsoleSetup C:\s\wixSharp\wixsharp\Source\src\WixSharp.Samples\Wix# Samples\External_UI\ConsoleSetup\ConsoleSetup.cs 56 Also ManagedUI\SilentBA.cs and wixsharp\Source\src\WixSharp.Samples\Wix# Samples\Managed Setup\Self-executable_Msi\app.config is missing in repository.

oleg-shilo commented 2 months ago

Sorry. Done

oleg-shilo commented 2 months ago

Done. The fix is released in v2.2.0

smaudet commented 1 month ago

SilentBA is still not present here on v2.2.0 (or latest wix4 release).

I have cobbled together a replacement @oleg-shilo I noticed you seem to have two of them? One in wixsharp.UI and one in wixsharp core that the netcore build references. I think maybe you have a symlink on disk or something and your git is not committing the file.

oleg-shilo commented 1 month ago

Thank you @smaudet. Indeed is is a mistake from my side. When I did the split Core vs Fx I had to split an move SilenBA and just forgot to add it to the repo. Thank you it's fixed now.


Did you mean to post in a different thread?

smaudet commented 1 month ago

Did you mean to post in a different thread?

What? Did you maybe mean this? https://github.com/oleg-shilo/wixsharp/discussions/1582

Not sure what else you could mean...

oleg-shilo commented 1 month ago

This thread is about "Error when specifying Package Platform as ARM64". But your post was not related to that so I am checking if you wanted to post it in a different thread and we need to transfer it there.

smaudet commented 1 month ago

@oleg-shilo no it was the right thread:

Also ManagedUI\SilentBA.cs and wixsharp\Source\src\WixSharp.Samples\Wix# Samples\Managed Setup\Self-executable_Msi\app.config

@talbotsk mentioned this two weeks ago.

I posted here because I was searching for SilentBA when I was trying to build it.