本文介绍了WiX Bundle bal:condition - util:RegistrySearch 变量始终为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果未安装第三方软件元素,我希望我的安装失败.我在 Bundle 中添加了一个带有 util:RegistrySearchbal:ConditionFragment,但我不能让它工作.ThirdPartyCOMLibraryInstalled 永远不会评估为真.我已经确认密钥存在,并且我用于 Key 的值是正确的 - 我从 regedit 中的选定密钥复制/粘贴了名称.日志中没有任何错误.

I want my install to fail if a third-party software element is not installed. I added a Fragment with a util:RegistrySearch and a bal:Condition to the Bundle, but I can't get it to work. ThirdPartyCOMLibraryInstalled never evaluates to true. I've confirmed that the key exists, and the value I use for Key is correct - I copy/pasted the name from the selected key in regedit. There aren't any errors in the log.

我正在 Windows 7 64 位的 Visual Studio 2012 中使用 WiXTools 3.7 构建安装程序,并在 Windows XP SP3 和 Windows 7 64 位上进行测试.

I'm building the installer with WiXTools 3.7 in Visual Studio 2012 on Windows 7 64-bit and testing on both Windows XP SP3 and Windows 7 64-bit.

在线搜索 util:RegistrySearch 的其他示例我遇到了条件测试表达式的以下替代形式.

Searching online for other examples for util:RegistrySearch I ran across the following alternative forms for the condition test expression.

  1. ThirdPartyCOMLibraryInstalled = 0 - 始终为 False
  2. ThirdPartyCOMLibraryInstalled <>1 - 始终为真
  1. ThirdPartyCOMLibraryInstalled = 0 - always False
  2. ThirdPartyCOMLibraryInstalled <> 1 - always True

这是 Bundle 代码:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
     xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">

    <Bundle Name="!(bind.packageName.MyApp)"
            Version="!(bind.packageVersion.MyApp)"
            Manufacturer="!(bind.packageManufacturer.MyApp)"
            UpgradeCode="a07ce1d5-a7ed-4d89-a7ee-fb13a5dd69ba"
            Copyright="Copyright (c) 2013 [Bundle/@Manufacturer]. All rights reserved."
            IconSourceFile="$(var.My_Application1.ProjectDir)MyCo.ico">

        <bal:Condition Message="ThirdParty Application COM Library Required. Please (re)install ThirdParty Application and ensure 'Windows API' and '.NET Components' are installed."
        >ThirdPartyCOMLibraryInstalled</bal:Condition>

        <Variable Name="InstallFolder"
                  Type="string"
                  Value="[ProgramFilesFolder]MyCo SystemsMy_Application"/>
        <BootstrapperApplicationRef
            Id="WixStandardBootstrapperApplication.HyperlinkLicense" >

            <bal:WixStandardBootstrapperApplication
                ThemeFile="ResourcesHyperlinkTheme.xml"
                LaunchTarget="[InstallFolder]My_Application.exe"
                LocalizationFile="ResourcesHyperlinkTheme.wxl"
                SuppressRepair="yes"
                SuppressOptionsUI="yes"
                LicenseUrl=""
                LogoFile="Resources/MyCoLogoWt64.png"

            />
        </BootstrapperApplicationRef>
        <Chain>
            <PackageGroupRef Id="NetFx40Redist"/>
            <MsiPackage Id ="MyApp"
                        Vital="yes"
                        Name="My Application"
                        SourceFile="$(var.MyApp_Install.TargetDir)MyApp_Install.msi">
                <MsiProperty Name="INSTALLLOCATION"
                             Value="[InstallFolder]" />
            </MsiPackage>
        </Chain>
    </Bundle>

    <Fragment>
      <util:RegistrySearch
            Variable="ThirdPartyCOMLibraryInstalled"
            Result="exists"
            Root="HKLM"
            Key="SOFTWAREClassesThirdPartyId.ServerCLSID"/>
    </Fragment>
</Wix>

推荐答案

根本问题是 RegistrySearch 位于一个单独的 Fragment 中,永远不会被引用.因为 Fragment 中的任何内容都没有被引用,所以链接器优化"了 Fragment 的内容,并且搜索不包含在您的 Bundle 中.

The root issue is that the RegistrySearch is in a separate Fragment that never gets referenced. Because nothing in the Fragment gets referenced the linker "optimizes away" the contents of the Fragment and the search is not included in your Bundle.

除此之外:您可能会争辩说,在 Condition 中的搜索中提到了对变量的引用,链接器应该能够确定搜索是必要的.但是,这并非在所有情况下都有效.

幸运的是,解决方案非常简单!您甚至必须从以下两种中选择一种:

Fortunately, the solution is quite simple! You even have to choose from one of two:

  1. RegistrySearch 元素移动到 Bundle 元素.
  2. Bundle 元素中添加 RegistrySearchRef 元素以引用 Fragment 中的 RegistrySearch.您还需要提供 RegistrySearchId 属性.
  1. Move the RegistrySearch element to the Bundle element.
  2. Add a RegistrySearchRef element in the Bundle element to reference the RegistrySearch in the Fragment. You will also need to give the RegistrySearch and Id attribute.

就个人而言,我喜欢选项二,我什至可能会将 Condition 移动到 Fragment 中,并将所有这些东西组合在一起.类似于:

Personally, I like option two and I would probably even move the Condition into the Fragment as well to group all that stuff together. Something akin to:

<Bundle ...>
   <util:RegistrySearchRef Id='SearchForThirdParty' />

   ...

</Bundle>

<Fragment>
   <util:RegistrySearch
          Id='SearchForThirdParty'
          Variable="ThirdPartyCOMLibraryInstalled"
          Result="exists"
          Root="HKLM"
          Key="SOFTWAREClassesThirdPartyId.ServerCLSID"/>

    <bal:Condition Message="ThirdParty Application COM Library Required. Please (re)install ThirdParty Application and ensure 'Windows API' and '.Net Components' are installed.">ThirdPartyCOMLibraryInstalled</bal:Condition>
  </Fragment>
</Wix>

应该可以的.

这篇关于WiX Bundle bal:condition - util:RegistrySearch 变量始终为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 19:47
查看更多