Use WIX_NATIVE_MACHINE to detect native architecture of target machine

This commit is contained in:
Eric StJohn 2021-10-05 22:35:57 -07:00
parent 1a39c5ae6e
commit dad4407de3
3 changed files with 25 additions and 23 deletions

View file

@ -20,7 +20,7 @@
<!-- Permit same path on non-ARM64 machines since past SDKs always wrote this value -->
<bal:Condition Message="The installation path for ARM64 SDK installations: &quot;[DOTNETHOME_ARM64]&quot; cannot be the same as for x64 SDK installations: &quot;[DOTNETHOME_X64]&quot;">
WixBundleInstalled OR (NOT DOTNETHOME_ARM64 ~= DOTNETHOME_X64) OR (NOT NativeProcessorArchitecture=&quot;ARM64&quot;) OR DOTNETHOMESIMILARITYCHECKOVERRIDE
WixBundleInstalled OR (NOT DOTNETHOME_ARM64 ~= DOTNETHOME_X64) OR (NOT NativeMachine=&quot;$(var.NativeMachine_arm64)&quot;) OR DOTNETHOMESIMILARITYCHECKOVERRIDE
</bal:Condition>
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.Foundation">
@ -76,21 +76,12 @@
Root="HKLM"
Key="SOFTWARE\dotnet\Setup\InstalledVersions\x64"
Value="InstallLocation" />
<!-- Determine native OS architecture -->
<util:RegistrySearch Id="CheckProcessorArchitecture_x64"
After="DotnetInstallLocation_x64"
Variable="NativeProcessorArchitecture"
Result="value"
Root="HKLM"
Key="SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Value="PROCESSOR_ARCHITECTURE" />
<!-- Check default location when on x64 OS-->
<util:FileSearch Id="DotnetExeSearch_x64"
After="CheckProcessorArchitecture_x64"
After="DotnetInstallLocation_x64"
Variable="DotnetExeExists_x64"
Condition="NOT DotnetInstallLocationExists_x64 AND NativeProcessorArchitecture=&quot;AMD64&quot;"
Condition="NOT DotnetInstallLocationExists_x64 AND (NOT NativeMachine OR NativeMachine=&quot;$(var.NativeMachine_x64)&quot;)"
Result="exists"
Path="[ProgramFiles64Folder]dotnet\dotnet.exe"/>
<util:DirectorySearch Id="DotnetExeLocation_x64"
@ -101,9 +92,9 @@
<!-- Check alternate location on non-x64 OS -->
<util:FileSearch Id="DotnetExeSearch_alt_x64"
After="CheckProcessorArchitecture_x64"
After="DotnetInstallLocation_x64"
Variable="DotnetExeExists_alt_x64"
Condition="NOT DotnetInstallLocationExists_x64 AND NOT NativeProcessorArchitecture=&quot;AMD64&quot;"
Condition="NOT DotnetInstallLocationExists_x64 AND NOT NativeMachine=&quot;$(var.NativeMachine_x64)&quot;"
Result="exists"
Path="[ProgramFiles64Folder]dotnet\x64\dotnet.exe"/>
<util:DirectorySearch Id="DotnetExeLocation_alt_x64"

View file

@ -5,23 +5,27 @@
<?define Platform = "$(sys.BUILDARCH)"?>
<?endif?>
<!-- InstallerArchitecture matches the expected values for PROCESSOR_ARCHITECTURE
https://docs.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details -->
<!-- InstallerNativeMachine matches the expected values for image file machine constants
https://docs.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants -->
<?if $(var.Platform)~=x86?>
<?define InstallerArchitecture="X86"?>
<?define InstallerNativeMachine=332?>
<?elseif $(var.Platform)~=x64?>
<?define InstallerArchitecture="AMD64"?>
<?define InstallerNativeMachine=34404?>
<?elseif $(var.Platform)~=arm64?>
<?define InstallerArchitecture="ARM64"?>
<?define InstallerNativeMachine=43620?>
<?else?>
<?error Unknown platform, $(var.Platform) ?>?
<?error Unknown platform, $(var.Platform) ?>
<?endif?>
<Fragment>
<!-- Identify when installing in emulation as when PROCESSOR_ARCHITECTURE does not match the installer architecture
https://docs.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details -->
<!-- Identify when installing in emulation as when WIX_NATIVE_MACHINE does not match the installer
native machine (where supported). Also detect running under WOW on x86 using VersionNT64,
since WIX_NATIVE_MACHINE cannot be retrieved on older Windows builds. -->
<SetProperty Action="Set_NON_NATIVE_ARCHITECTURE" Id="NON_NATIVE_ARCHITECTURE" Value="true" Before="CostFinalize">
NOT %PROCESSOR_ARCHITECTURE="$(var.InstallerArchitecture)"
<?if $(var.Platform)~=x86?>
VersionNT64 OR
<?endif?>
WIX_NATIVE_MACHINE AND NOT WIX_NATIVE_MACHINE="$(var.InstallerNativeMachine)"
</SetProperty>
</Fragment>

View file

@ -15,7 +15,14 @@
<?define LCID = "$(var.ProductLanguage)"?>
<?define DowngradeErrorMessage = "A newer version is already installed; please uninstall it and re-run setup."?>
<!-- NativeMachine values match the expected values for image file machine constants
https://docs.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants -->
<?define NativeMachine_x86=332?>
<?define NativeMachine_x64=34404?>
<?define NativeMachine_arm64=43620?>
<?define Platform = "$(sys.BUILDARCH)" ?>
<?if $(var.Platform)=x86?>
<?define PlatformToken="X86"?>
<?define WixQuietExec="WixQuietExec"?>