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

Error when specifying Package Platform as ARM64 #1557

Closed
artlaskow opened this issue Jun 13, 2024 · 14 comments
Closed

Error when specifying Package Platform as ARM64 #1557

artlaskow opened this issue Jun 13, 2024 · 14 comments

Comments

@artlaskow
Copy link

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
Copy link
Owner

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

  • Set 64 bitness and the installer version required by the wix.exe:
    project.Platform = Platform.x64;
    project.InstallerVersion = 500;
    
  • Second step is manual.
    Instead of building msi build the batch file for building msi:
    project.BuildMsiCmd("msi.build.cmd");
    
    After building the project the batch file will be created and if you execute it the msi will be built. Though before executing the batch file you will need to replace the -arch x64 with -arch arm64. That's why we need to do a manual build with the batch file.

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link

talbotsk commented Jun 20, 2024

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 oleg-shilo added the bug label Jun 21, 2024
@oleg-shilo
Copy link
Owner

oleg-shilo commented Jun 21, 2024

@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

oleg-shilo added a commit that referenced this issue Jun 21, 2024
- Issue #1557: Error when specifying Package Platform as ARM64
@talbotsk
Copy link

talbotsk commented Jun 24, 2024

@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
Copy link
Owner

Sorry. Done

oleg-shilo added a commit that referenced this issue Jun 29, 2024
- The whole round trip implementation for the elevated events (#1565, #1567). Not integrated to the API yet
- added `restart elevated` routine for custom BA sample
- Issue #1554: Add custom Wizard-like Installer to Bundle / Burn Installer
- Implemented `MsiExePackage`. Triggered by #1554
  Dedicates sample `WixBootstrapper_MsiEmbeddedUI` shows how to use it
  ```C#
  var bootstrapper =
        new Bundle("Managed Product Bundle",
                    new MsiExePackage(msi)
                    {
                        Name = "ManagedProduct",
                    });
  ```

- Issue #1557: Error when specifying Package Platform as ARM64
- WiX4: added `WixProject.WixBuildCommandGenerated` even. Triggered by #1557
- Added `CommonTasks.MapAsDeferredProperty` extension method:
  ```C#
  project.MapAsDeferredProperty("MYPROPERTY");
  // instead of
  project.DefaultDeferredProperties += ",MYPROPERTY";
  ```
- Added `string.CompleSelfHostedMsi` extension for building self executable msi files:
  ```C#
  msi.CompleSelfHostedMsi(msi + ".exe");
  ```
- added calling `dotnet tool restore` when using wix as a local tool. Triggered by #1546
oleg-shilo added a commit that referenced this issue Jun 29, 2024
- Implemented `MsiExePackage`. Triggered by #1554
  The dedicated sample `WixBootstrapper_MsiEmbeddedUI` shows how to use it
  ```C#
  var bootstrapper =
        new Bundle("Managed Product Bundle",
                    new MsiExePackage(msi)
                    {
                        Name = "ManagedProduct",
                    });
  ```

- Issue #1557: Error when specifying Package Platform as ARM64
- Added `restart elevated` routine for custom BA sample
- Added `WixProject.WixBuildCommandGenerated` event. Can be used to manipulate `wix.exe` command line arguments. Triggered by #1557
- Added `CommonTasks.MapAsDeferredProperty` extension method:
  ```C#
  project.MapAsDeferredProperty("MYPROPERTY");
  // instead of
  project.DefaultDeferredProperties += ",MYPROPERTY";
  ```
- Added `string.CompleSelfHostedMsi` extension for building self executable msi files:
  ```C#
  msi.CompleSelfHostedMsi(msi + ".exe");
  ```
- added calling `dotnet tool restore` when using wix as a local tool. Triggered by #1546
@oleg-shilo
Copy link
Owner

Done.
The fix is released in v2.2.0

@smaudet
Copy link

smaudet commented Jul 9, 2024

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
Copy link
Owner

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
Copy link

smaudet commented Jul 10, 2024

Did you mean to post in a different thread?

What? Did you maybe mean this? #1582

Not sure what else you could mean...

@oleg-shilo
Copy link
Owner

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
Copy link

smaudet commented Jul 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants