msiexec 和手动安装同一个 wixinstaller,而两者都应该允许覆盖 installdir无法让它工作

问题描述

我们有一些通过 MSI 安装程序分发的软件。只要手动运行此安装程序,一切似乎都运行良好。但是,出于测试目的,我们尝试在设置期间使用 msiexec

在我们的测试框架内运行相同的安装程序
string targetDirectory = @"C:\git\00_DATA\; // For testing purposes
string arguments = "/qn /a \"" + msiFile + "\" TARGETDIR=\"" + targetDirectory + "\" /l*V \"" + logLocation + "\"";
Directory.CreateDirectory(targetDirectory);
Process process = Process.Start("msiexec",arguments);

MSI 安装程序大致如下所示:

Product Id="*" Name="$(var.productName)" Language="1033" Version="$(var.productVersion)" Manufacturer="$(var.companyName)" UpgradeCode="$(var.productUpgradeCode)">
    <!--package requires installer 400 (4.0. included from vista and up). install on machine scope-->
    <Package Id="*" InstallerVersion="400" Compressed="yes" InstallScope="perMachine" />

    <!--Require administartor access rights-->
    <Condition Message="You need to be an administrator to install $(var.productName).">
      Privileged
    </Condition>

    <!--Check if this is an update-->
    <MajorUpgrade AllowSameVersionUpgrades="yes" disallow="yes" DowngradeErrorMessage="A later version of the package is already installed. Setup will Now exit." disallowUpgradeErrorMessage="Please uninstall the  package using the control panel before installing a newer version."/>

    <!--Enforce all resources to be dumped into a cab file,enabled very light compression to save on speed but take easy shortcuts to make it a little smaller-->
    <Media Id="1" Cabinet="data.cab" EmbedCab="yes" CompressionLevel="mszip"/>

    <!--Directory structure for installation,root-->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="$(var.programFolder)">
        <Directory Id="$(var.companyName)" Name="$(var.companyName)">
          <Directory Id="INSTALLDIR" Name="$(var.ProductName)">

            <!--Add installation directory as component. This way it will clean up all of the module in one go,instead of having to set a delete on every single file-->
            <Component Id="INSTALLDIR_comp" Guid="920C1EF1-DFAA-43FB-84A6-FA50EC0AD661">
              <CreateFolder>
                <Permission User="Users" GenericAll="yes" />
              </CreateFolder>
            </Component>

          </Directory>
        </Directory>
      </Directory>
    </Directory>

    <!--Feaatures are 'what to install'. Only support a full install for Now-->
    <Feature Id="Complete" Title="$(var.productName)" Description="Full installation" display="expand" Level="1" ConfigurableDirectory="INSTALLDIR">
      <ComponentRef Id="INSTALLDIR_comp"/>
      <ComponentRef Id="Product_Component"/>
      <ComponentGroupRef Id="INSTALLDIR_comp"/>
    </Feature>

    <!--Set pictures,banners ect for screen-->
    <WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="dialog.bmp"/>

    <!--Set programs and installer icon-->
    <Icon Id="installer_icon" SourceFile="installer.ico"/>
    <Property Id="ARPPRODUCTICON" Value="installer_icon"/>

    <!--Property with installation folder location (from and to ui)-->
    <Property Id="WIXUI_INSTALLDIR">INSTALLDIR</Property>

    <!-- Variable with the location of the license -->
    <WixVariable Id="WixUILicenseRtf" Value="license.rtf" />

    <!--UI-->
    <UI>
      <UIRef Id="WixUI_InstallDir" />
      <UIRef Id="WixUI_ErrorProgresstext" />
    </UI>
  </Product>
</Wix>

当手动运行 installdir 对话框时,我可以很好地覆盖 INSTALDIR,提供 programfiles// 位置为认值。

然而,当通过 msiexec 运行时,INSTALLDIR 似乎没有作为有效参数工作,导致我无法覆盖它,导致它始终位于认位置:programfiles// .

作为替代方案,我收到了用以下内容替换该位的建议:

<!-- Set the installdir after the launchconditions,we have to this otherwise the installdir has subdirs when doing an administrative install (no launch conditions event in administrative install).-->
<SetProperty Id="INSTALLDIR" After="LaunchConditions" Value="[$(var.programFolder)]\$(var.companyName)\$(var.productName)"/>

<!--Directory structure for installation,root-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.programFolder)">
<Directory Id="INSTALLDIR">

解决了我在使用 msiexec 时遇到的问题,允许我使用 TARGETDIR 参数指定要安装的位置。但是,wix_UI 位似乎不再通过此更改覆盖手动安装中的任何内容

在尝试不同的解决方案(在自定义操作和其他尝试中添加定义参数以覆盖 installdir)为此苦苦挣扎了一整天之后,我想我应该去伟大的互联网寻求帮助:)

这里有人能指出我正确的方向并给我一些指导吗?或者甚至提供一个工作示例/代码片段,允许我使用 1 和相同的安装程序进行手动使用 + msiexec 使用,同时仍然能够提供认位置,以防在参数中未指定任何内容

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)