Reputation: 111
As part of installation of a WPF application using .NET 6 and a WiX installer, I would like to check whether the .NET 6 runtime is installed.
WiX provides pre-defined properties to check this for .NET framework but nothing for .NET Core and beyond so I am attempting to check for the presence of a registry key.
There is a registry key that can be checked under: HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost\Version
However, if I uninstall the runtime the registry key does not get removed, is there any other reliable way to check whether the runtime is installed, as well as which version is installed?
Upvotes: 11
Views: 13445
Reputation: 959
For Wix4 bundles, you need DotNetCoreSearch instead of DotNetCompatibilityCheck. You use it like this:
<Wix ... xmlns:netfx="http://wixtoolset.org/schemas/v4/wxs/netfx">
<Fragment>
<netfx:DotNetCoreSearch Id="Dotnet6DesktopX86Version" Variable="Dotnet6DesktopX86Version"
RuntimeType="desktop" Platform="x86" MajorVersion="6"/>
<PackageGroup Id="Dotnet6DesktopX86Redist">
<ExePackage DetectCondition="Dotnet6DesktopX86Version >= v6.0.13"
.../>
</PackageGroup>
</Fragment>
DotNetCoreSearch reads the current version of dotnet 6 desktop x86, and then DetectCondition is false if it is below 6.0.13 There is a more complete example in the wix source code here.
Upvotes: 10
Reputation: 2466
April 2023
With the official release of WiX 4, it is now natively supported to check if the .NET runtime (core, desktop, or aspnet) is installed on the computer via the WiX 4 Netfx wixextension: https://wixtoolset.org/docs/schema/netfx/dotnetcompatibilitycheck/
Example usage:
<Fragment>
<netfx:DotNetCompatibilityCheck Id="netCoreStatus"
Property="NETCORESTATUS" RollForward="latestMajor"
RuntimeType="core" Version="6.0.1" Platform="x64" />
<Launch Condition="Installed OR NETCORESTATUS="0""
Message="[ProductName] requires Microsoft .NET Core - 6.0.1 or greater." />
</Fragment>
Internally, it uses the same packages I linked down below to run the NetCoreCheck executable.
Original Answer
WiX 3 currently doesn't handle this natively. It is being worked on for WiX v4 (GitHub issue). Reading the issue led me to these tools as a current workaround.
https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x86
https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x64
You can use the files inside of these packages to check for a runtime. Either by running NetCoreCheck.exe
directly or using the custom action DLL provided.
NetCoreCheck.exe -h
to see help. But you'll want something like this:
netcorecheck --runtimename Microsoft.NetCore.App --runtimeversion 6.0.0
I don't know how to use the custom action dll but I do see it has two DLL exports.
ordinal hint RVA name
1 0 00001500 CheckNETRuntime
2 1 00002260 get_hostfxr_path
Upvotes: 14
Reputation: 314
You may use the Custom Action DLL mentioned in Hank's answer if you want to integrate this in your WiX project.
You can use the NuGet package to obtain the dll. Unfortunately there seems to be no documentation in existence for this DLL, so I used the source code to figure out how this works.
First you need to define a few properties that are used as input parameters for the .NET runtime check, and for the result of the check.
<Property Id="CheckNETRuntime_Framework" Value="Microsoft.AspNetCore.App" />
<Property Id="CheckNETRuntime_Version" Value="6.0.0" />
<Property Id="CheckNETRuntime_Result" />
CheckNETRuntime_Framework
is the framework to search for. There are currently 3 options:
CheckNETRuntime_Version
is the version of .NET to look for.
The result will be stored in CheckNETRuntime_Result
. A value of 0
indicates the runtime was found, any other value indicates it was not found.
To run the custom action, do this:
<Binary Id="CustomActions" SourceFile="NetCoreCheckCA.dll" /> <!-- This should be the path to the dll -->
<CustomAction Id="CheckRuntime" Return="ignore" BinaryKey="CustomActions" DllEntry="CheckNETRuntime" />
<InstallExecuteSequence>
<Custom Action="CheckRuntime" Before="LaunchConditions" />
</InstallExecuteSequence>
<InstallUISequence>
<Custom Action="CheckRuntime" Before="LaunchConditions" />
</InstallUISequence>
Note: you need to add Return="ignore"
if you do not want the installer to fail when the runtime was not found (as the return value if not 0, which indicates a failure).
The CheckNETRuntime_Result
property can be used elsewhere in your setup, for example you could use it in a condition:
<Condition Message=".NET 6 runtime is not installed">
<![CDATA[CheckNETRuntime_Result=0]]>
</Condition>
Upvotes: 6