Skip to content

Commit

Permalink
Adding detection and retargeting of DOTNETHOME (#7785)
Browse files Browse the repository at this point in the history
* Adding detection and retargeting of DOTNETHOME

When x64 is installed on non-x64 machine, place in an x64 subdirectory.

* Remove test value of dotnet folder

* Fix ProgramFilesFolder preprocessor variable usage

* Refactor Set_DOTNETHOME_x64 into a single shared source file

* Add CA ID for INSTALLING_IN_EMULATION.

* Define Platform consistently

* Move workload registration to platform specific

* Refactor INSTALLING_IN_EMULATION property

Don't need to use a registry search since environment of the MSIServer
process can be read (TBD pending reccomendation from MSI team).

Also make property work for any architecture, in case we wish to use
it more generically (EG: to condition PATH entry in host installer).

* Make platform comparison case insensitive

* Respond to feedback
  • Loading branch information
ericstj authored Sep 3, 2021
1 parent 00949c5 commit 0ec8dba
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/Common/wix/dotnethome_x64.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?ifndef Platform?>
<?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 -->
<?if $(var.Platform)~=x86?>
<?define InstallerArchitecture="X86"?>
<?elseif $(var.Platform)~=x64?>
<?define InstallerArchitecture="AMD64"?>
<?elseif $(var.Platform)~=arm64?>
<?define InstallerArchitecture="ARM64"?>
<?else?>
<?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 -->
<SetProperty Action="Set_NON_NATIVE_ARCHITECTURE" Id="NON_NATIVE_ARCHITECTURE" Value="true" Before="CostFinalize">
NOT %PROCESSOR_ARCHITECTURE="$(var.InstallerArchitecture)"
</SetProperty>
</Fragment>

<?if $(var.Platform)~=x64?>
<Fragment>
<!-- When running in a non-native architecture and user hasn't specified install directory,
install to an x64 subdirectory.
This is only define for x64, since x86 has redirection and no other native architecture can install ARM64 today -->
<SetProperty Action="Set_DOTNETHOME_NON_NATIVE_ARCHITECTURE" Id="DOTNETHOME" Value="[ProgramFiles64Folder]dotnet\x64\" After="Set_NON_NATIVE_ARCHITECTURE">
NON_NATIVE_ARCHITECTURE AND NOT DOTNETHOME
</SetProperty>
</Fragment>
<?endif?>
</Wix>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<None Include="build/**/*.*" Pack="true">
<PackagePath>build</PackagePath>
</None>
<None Include="..\Common\wix\dotnethome_x64.wxs" Link="build\wix\product\dotnethome_x64.wxs" PackagePath="%(Link)" Pack="true" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

<?include "..\variables.wxi" ?>
Expand Down Expand Up @@ -51,6 +52,9 @@
<Directory Id="DOTNETHOME" Name="dotnet" />
</Directory>
</Directory>
</Fragment>

<?if $(var.Platform)~=x64?>
<CustomActionRef Id="Set_DOTNETHOME_NON_NATIVE_ARCHITECTURE" />
<?endif?>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<WixExtensions Include="WixUtilExtension.dll" />

<WixSrcFile Include="$(MSBuildThisFileDirectory)product/product.wxs" />
<WixSrcFile Include="$(MSBuildThisFileDirectory)product/dotnethome_x64.wxs" />
<WixSrcFile Include="$(MSBuildThisFileDirectory)product/provider.wxs" />
</ItemGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public override bool Execute()
List<string> sourceFiles = new();
string msiSourcePath = Path.Combine(MsiDirectory, $"{nupkg.Id}", $"{nupkg.Version}", platform);
sourceFiles.Add(EmbeddedTemplates.Extract("DependencyProvider.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("dotnethome_x64.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("ManifestProduct.wxs", msiSourcePath));

string EulaRtfPath = Path.Combine(msiSourcePath, "eula.rtf");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ protected IEnumerable<ITaskItem> Generate(string sourcePackage, string swixPacka
string msiSourcePath = Path.Combine(MsiDirectory, $"{nupkg.Id}", $"{nupkg.Version}", platform);
sourceFiles.Add(EmbeddedTemplates.Extract("DependencyProvider.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("Directories.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("dotnethome_x64.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("Product.wxs", msiSourcePath));
sourceFiles.Add(EmbeddedTemplates.Extract("Registry.wxs", msiSourcePath));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<EmbeddedResource Include="Misc\*.*" />
<EmbeddedResource Include="MsiTemplate\*.wxs" />
<EmbeddedResource Include="MsiTemplate\*.wxi" />
<EmbeddedResource Include="..\..\Common\wix\dotnethome_x64.wxs" Link="MsiTemplate\dotnethome_x64.wxs" />
<EmbeddedResource Include="SwixTemplate\*.swr" />
<EmbeddedResource Include="SwixTemplate\*.swixproj" />
<EmbeddedResource Include="SwixTemplate\*.vsmanproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
</Directory>
</Directory>
</Directory>

<?if $(var.Platform)~=x64?>
<CustomActionRef Id="Set_DOTNETHOME_NON_NATIVE_ARCHITECTURE" />
<?endif?>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
</Directory>
</Directory>

<?if $(var.Platform)~=x64?>
<CustomActionRef Id="Set_DOTNETHOME_NON_NATIVE_ARCHITECTURE" />
<?endif?>

<MediaTemplate CompressionLevel="high" EmbedCab="yes" />

<!-- Record the original package used to generate the MSI -->
Expand Down

0 comments on commit 0ec8dba

Please sign in to comment.