peter reay
peter reay

Reputation: 669

Install .NET runtime and avoid 0x80070666 another version of this product is already installed, return code 0x666

I'm installing a .NET 6 desktop application. As part of the installer I install the .NET 6.0.10 desktop runtime, using WiX:

<ExePackage
  SourceFile="$(var.ProjectDir)\ThirdParty\windowsdesktop-runtime-6.0.10-win-x64.exe"
  InstallCommand="/q /ACTION=Install"
  RepairCommand="/q ACTION=Repair /hideconsole"
  UninstallCommand="/q ACTION=Uninstall /hideconsole" />

This works fine if there is no pre-existing 6.0.x version of the runtime installed. It also works fine if 6.0.10 is already installed. However if there is a different 6.0.x version installed, the installer fails:

Error 0x80070666: Process returned error: 0x666

With a message in the UI "another version of this product is already installed".

Does anyone know of a simple way in WiX I can upgrade earlier versions or skip the package if a later version is already installed?

Upvotes: 2

Views: 2401

Answers (2)

peter reay
peter reay

Reputation: 669

This owes a lot to Vivek's answer, but that had problems - the registry key mentioned there is overwritten by the last version of .NET you installed, and couldn't handle having multiple (6.0, 7.0, etc) frameworks installed.

The solution I've ended with has hardcoded searches for future versions of 6.0.x, which isn't ideal, but is the best I've come up with.

<!-- We won't attempt to install .NET 6.0.x (x64) if any of these versions are already present
     If there's ever a 6.0.21 or higher we'll have to extend this list -->
<util:DirectorySearch Id="DSNet6x64v6010" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.10" Variable="Net6x64v6010" />
<util:DirectorySearch Id="DSNet6x64v6011" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.11" Variable="Net6x64v6011" />
<util:DirectorySearch Id="DSNet6x64v6012" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.12" Variable="Net6x64v6012" />
<util:DirectorySearch Id="DSNet6x64v6013" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.13" Variable="Net6x64v6013" />
<util:DirectorySearch Id="DSNet6x64v6014" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.14" Variable="Net6x64v6014" />
<util:DirectorySearch Id="DSNet6x64v6015" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.15" Variable="Net6x64v6015" />
<util:DirectorySearch Id="DSNet6x64v6016" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.16" Variable="Net6x64v6016" />
<util:DirectorySearch Id="DSNet6x64v6017" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.17" Variable="Net6x64v6017" />
<util:DirectorySearch Id="DSNet6x64v6018" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.18" Variable="Net6x64v6018" />
<util:DirectorySearch Id="DSNet6x64v6019" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.19" Variable="Net6x64v6019" />
<util:DirectorySearch Id="DSNet6x64v6020" Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.20" Variable="Net6x64v6020" />

<!-- And same for the x86 version -->
<util:DirectorySearch Id="DSNet6x86v6010" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.10" Variable="Net6x86v6010" />
<util:DirectorySearch Id="DSNet6x86v6011" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.11" Variable="Net6x86v6011" />
<util:DirectorySearch Id="DSNet6x86v6012" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.12" Variable="Net6x86v6012" />
<util:DirectorySearch Id="DSNet6x86v6013" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.13" Variable="Net6x86v6013" />
<util:DirectorySearch Id="DSNet6x86v6014" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.14" Variable="Net6x86v6014" />
<util:DirectorySearch Id="DSNet6x86v6015" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.15" Variable="Net6x86v6015" />
<util:DirectorySearch Id="DSNet6x86v6016" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.16" Variable="Net6x86v6016" />
<util:DirectorySearch Id="DSNet6x86v6017" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.17" Variable="Net6x86v6017" />
<util:DirectorySearch Id="DSNet6x86v6018" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.18" Variable="Net6x86v6018" />
<util:DirectorySearch Id="DSNet6x86v6019" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.19" Variable="Net6x86v6019" />
<util:DirectorySearch Id="DSNet6x86v6020" Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\6.0.20" Variable="Net6x86v6020" />

<Chain>
  <ExePackage
      SourceFile="$(var.ProjectDir)\ThirdParty\windowsdesktop-runtime-6.0.10-win-x64.exe"
      InstallCommand="/q /ACTION=Install"
      RepairCommand="/q ACTION=Repair /hideconsole"
      UninstallCommand="/q ACTION=Uninstall /hideconsole"
      InstallCondition="NOT Net6x64v6010 AND NOT Net6x64v6011 AND NOT Net6x64v6012 AND NOT Net6x64v6013 AND NOT Net6x64v6014 AND NOT Net6x64v6015 AND NOT Net6x64v6016 AND NOT Net6x64v6017 AND NOT Net6x64v6018 AND NOT Net6x64v6019 AND NOT Net6x64v6020 AND NOT Remove"/>
  <ExePackage
      SourceFile="$(var.ProjectDir)\ThirdParty\windowsdesktop-runtime-6.0.10-win-x86.exe"
      InstallCommand="/q /ACTION=Install"
      RepairCommand="/q ACTION=Repair /hideconsole"
      UninstallCommand="/q ACTION=Uninstall /hideconsole"
      InstallCondition="NOT Net6x86v6010 AND NOT Net6x86v6011 AND NOT Net6x86v6012 AND NOT Net6x86v6013 AND NOT Net6x86v6014 AND NOT Net6x86v6015 AND NOT Net6x86v6016 AND NOT Net6x86v6017 AND NOT Net6x86v6018 AND NOT Net6x86v6019 AND NOT Net6x86v6020 AND NOT Remove"/>
</Chain>

Upvotes: 0

Vivek
Vivek

Reputation: 1079

You need to use DetectCondition attribute.

<Variable Name="NetCore6Version" Type="numeric" Value="1.0.0" />
<Variable Name="MinNetCore6Version" Type="numeric" Value="6.0.10" />
<util:RegistrySearch Root="HKLM" Key="SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost" Value="Version" 
 Variable="NetCore6Version" /> 

<ExePackage
  SourceFile="$(var.ProjectDir)\ThirdParty\windowsdesktop-runtime-6.0.10-win-x64.exe"
  InstallCommand="/q /ACTION=Install"
  RepairCommand="/q ACTION=Repair /hideconsole"
  UninstallCommand="/q ACTION=Uninstall /hideconsole"
  DetectCondition="NetCore6Version &lt;=MinNetCore6Version"
  InstallCondition="NetCore6Version &gt;MinNetCore6Version" />

Upvotes: 1

Related Questions