在bootstrapper中管理先决条件版本

时间:2016-07-25 15:12:36

标签: c# bootstrapper prerequisites

我想使用visualstrudio 2015为应用程序C#创建一个引导程序。我想为SharedManagementObject设置一个先决条件(来自Microsoft,已下载that direct link)。我按照说明进行操作 the microsoft website

有我的product.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Product
  xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
  ProductCode="Custom.Bootstrapper.SharedManagementObjects2014x86">

  <RelatedProducts>
    <DependsOnProduct Code="Custom.Bootstrapper.SQLSysClrTypes2014x86" />
  </RelatedProducts>

  <PackageFiles>
    <PackageFile Name="SharedManagementObjects2014x86.msi"/>
  </PackageFiles>

  <InstallChecks>
    <MsiProductCheck Product="IsMsiInstalled" 
      Property="{4E6202DE-B996-4736-A64B-09EE2A8469E6}"/>
  </InstallChecks>

  <Commands>
    <Command PackageFile="SharedManagementObjects2014x86.msi" Arguments="">

      <InstallConditions>
        <BypassIf Property="IsMsiInstalled"
          Compare="ValueGreaterThan" Value="0"/>
        <FailIf Property="AdminUser" 
          Compare="ValueNotEqualTo" Value="True"
         String="NotAnAdmin"/>
      </InstallConditions>

      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="1641" Result="SuccessReboot"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <DefaultExitCode Result="Fail" String="GeneralFailure"/>
      </ExitCodes>
    </Command>
  </Commands>
</Product>

在安装程序中,一个对话框正确地要求安装SharedManagementObjects2014x86.msi,但我有两个问题:

  • 在与x86不兼容的CPU上,安装运行但失败。是否有指令检查CPU并仅在x86上安装?
  • 在x86 CPU上,安装正常。但是如果我重新运行setup.exe,则会再次安装SharedManagementObjects2014x86.msi。为什么<BypassIf Property="IsMsiInstalled" Compare="ValueGreaterThan" Value="0"/>无效?

坦克你

1 个答案:

答案 0 :(得分:1)

我终于找到了答案

  • 不重新安装:检查注册表

  • 根据CPU安装:检查ProcessorArchitecture

我的代码:

<?xml version="1.0" encoding="utf-8" ?>
<Product
    xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
    ProductCode="Custom.Bootstrapper.SharedManagementObjects2014">

    <RelatedProducts>
        <DependsOnProduct Code="Custom.Bootstrapper.SQLSysClrTypes2014" />
    </RelatedProducts>

    <PackageFiles>
        <PackageFile Name="SharedManagementObjects2014x64.msi"/>
        <PackageFile Name="SharedManagementObjects2014x86.msi"/>
    </PackageFiles>

    <InstallChecks>
        <!-- Check registry -->
        <RegistryCheck Property="IsMsiInstalled"
         Key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion"
         Value="Version" />
    </InstallChecks>

    <Commands>
        <!-- Install for x86 : ProcessorArchitecture = Intel -->
        <Command PackageFile="SharedManagementObjects2014x86.msi" Arguments="">    
            <InstallConditions>
                <BypassIf Property="IsMsiInstalled"
                 Compare="ValueGreaterThan" Value="0"/>
                <BypassIf Property="ProcessorArchitecture"
                 Compare="ValueNotEqualTo" Value="Intel"/>
                <FailIf Property="AdminUser" 
                 Compare="ValueNotEqualTo" Value="True"
                 String="NotAnAdmin"/>
            </InstallConditions>

            <ExitCodes>
                <ExitCode Value="0" Result="Success"/>
                <ExitCode Value="1641" Result="SuccessReboot"/>
                <ExitCode Value="3010" Result="SuccessReboot"/>
                <DefaultExitCode Result="Fail" String="GeneralFailure"/>
            </ExitCodes>
        </Command>

        <!-- Install for x64 : ProcessorArchitecture = amd64 -->
        <Command PackageFile="SharedManagementObjects2014x64.msi" Arguments="">    
            <InstallConditions>
                <BypassIf Property="IsMsiInstalled"
                 Compare="ValueGreaterThan" Value="0"/>
                <BypassIf Property="ProcessorArchitecture"
                 Compare="ValueNotEqualTo" Value="amd64"/>
                <FailIf Property="AdminUser" 
                 Compare="ValueNotEqualTo" Value="True"
                 String="NotAnAdmin"/>
            </InstallConditions>

            <ExitCodes>
                <ExitCode Value="0" Result="Success"/>
                <ExitCode Value="1641" Result="SuccessReboot"/>
                <ExitCode Value="3010" Result="SuccessReboot"/>
                <DefaultExitCode Result="Fail" String="GeneralFailure"/>
            </ExitCodes>
        </Command>
    </Commands>
</Product>