﻿<?xml version="1.0" encoding="utf-8"?>
<Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="Microsoft.SqlServer.SqlLocalDB.15.0">
  <InstallChecks>
    <FileCheck
      Property="sqllocaldbVersion"
      FileName="sqlservr.exe"
      SearchPath="Program Files\Microsoft SQL Server\150\LocalDB\Binn"
      SpecialFolder="WindowsVolume"
     />
    <RegistryCheck
      Property="VersionFullCheck"
      Key="HKLM\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
      Value="Version" 
     />
  </InstallChecks>

  <PackageFiles CopyAllPackageFiles="false">
    <PackageFile
      Name="x64\sqllocaldb.msi"
      HomeSite="sqllocaldb_64"
			PublicKey="0"
     />

    <PackageFile
      Name="vc_redist.x64.exe"
      HomeSite="https://aka.ms/vs/16/release/14.28.29325/VC_Redist.x64.exe"
			PublicKey="0"
      />
  </PackageFiles>

  <Commands Reboot="Defer">
    <Command PackageFile="vc_redist.x64.exe" Arguments=' /q '>
      <InstallConditions>
        <BypassIf Property="VersionFullCheck" Compare="ValueGreaterThanOrEqualTo" Value="v14.25.28508"/>
        <!-- Block install on any platform other than x64 -->
        <FailIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="AMD64" String="InvalidPlatformOS"/>
        <!-- Block install on Vista or below -->
        <FailIf Property="VersionNT" Compare="VersionLessThan" Value="6.00" String="InvalidPlatformOS"/>
      </InstallConditions>

      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>

    <Command PackageFile="x64\sqllocaldb.msi" Arguments="IACCEPTSQLLOCALDBLICENSETERMS=YES" EstimatedInstallSeconds="90">
      <InstallConditions>
        <BypassIf Property="sqllocaldbVersion" Compare="VersionGreaterThanOrEqualTo" Value="2019.150.2000.5"/>
        <!-- Block install on any platform other than x64 -->
        <FailIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64" String="InvalidPlatformOS"/>
        <!-- Block install on pre Win10 -->
        <FailIf Property="VersionNT" Compare="VersionLessThan" Value="10.00" String="InvalidPlatformOS"/>
      </InstallConditions>

      <ExitCodes>
        <ExitCode Value="0" Result="Success" />
        <ExitCode Value="1641" Result="SuccessReboot" />
        <ExitCode Value="3010" Result="SuccessReboot" />
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>
  </Commands>

</Product>

