在WiX 3.7中将绝对路径与相对路径组合在一起

时间:2013-04-26 19:57:01

标签: wix wix3 wix3.7

我正在尝试使用RemoveFolderEx在卸载应用程序时从我的安装文件夹中删除一级文件夹。这是我的,但它不起作用:

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="MyAppBaseFolder" Name="MyAppID">
          <Directory Id="INSTALLFOLDER" Name="MyAppLauncher">
            <Directory Id="UPDATESCRIPTSFOLDER" Name="Scripts" />
            <Component Id="CleanupMainApplicationFolder" Guid="*">
              <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Name="Path" Type="string" Value="${path::getfullpath(path::combine([INSTALLFOLDER],'..\MyApp'))}" KeyPath="yes" />
              <util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
            </Component>
          </Directory>
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyApp ID"/>
      </Directory>
    </Directory>
  </Fragment>

MSI将构建正常,但是当我运行设置时,它似乎在RegistryValue元素上失败并抱怨路径中的“..”。我正在制作的字符串就像:"C:\Program Files (X86)\MyApp ID\MyAppLauncher\..\MyApp"。我需要它来解决:"C:\Program Files (X86)\MyApp ID\MyApp"

我对${path:: ... }的东西不太熟悉。我看到了${path::combine()}的几个例子,所以我想我认为它可以在.NET中与getfullpath一起使用。也许它确实如此,我的语法错了?

谢谢!

编辑:对不起,我从BUILDING WIX收到${path::combine...内容,但没有完全阅读该文章的内容。它与wxs文件无关,它适用于NAnt(如Rob所述)。所以我想我的问题就是这样:我如何组合和解决绝对和相对路径,如C:\Program files (X86)\MyApp ID\MyAppLauncher\..\MyApp。感谢

EDIT2:再次感谢Rob,我非常关注解决我甚至没有考虑最明显解决方案的路径,即简单地引用一个新的<Directory元素。我现在用以下代码清理2个文件夹:

  <Property Id="APPLICATIONFOLDER">
    <RegistrySearch Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Root="HKLM" Type="raw" Id="APPLICATIONFOLDER_REGSEARCH" Name="Path" />
  </Property>

  <Property Id="PRINTERFOLDER">
    <RegistrySearch Key="SOFTWARE\MyApp ID\MyApp ID Printer" Root="HKLM" Type="raw" Id="PRINTERFOLDER_REGSEARCH" Name="Path" />
  </Property>

...

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="MyAppBaseFolder" Name="MyAppID">
          <Directory Id="INSTALLFOLDER" Name="MyAppLauncher">
            <Directory Id="UPDATESCRIPTSFOLDER" Name="Scripts" />
            <Component Id="CleanupMainApplicationFolder" Guid="*">
              <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Name="Path" Type="string" Value="[LM_INSTALLFOLDER]" KeyPath="yes" />
              <util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />

              <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Printer" Name="Path" Type="string" Value="[LMP_INSTALLFOLDER]" />
              <util:RemoveFolderEx On="uninstall" Property="PRINTERFOLDER" />
            </Component>
          </Directory>
          <Directory Id="LM_INSTALLFOLDER" Name="MyApp" >
          </Directory>
          <Directory Id="LMP_INSTALLFOLDER" Name="MyAppPrinter" >
          </Directory>
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyApp ID"/>
      </Directory>
    </Directory>
  </Fragment>

1 个答案:

答案 0 :(得分:3)

RegistryValue/@Value中的语法看起来像NAnt或其他东西。目前尚不清楚是什么解释,但Windows安装程序不会。您有几个选项可以使注册表值正确。首先,将RegistryValue元素更改为:

<RegistryValue Root="HKLM"
               Key="SOFTWARE\MyApp ID\MyApp ID Windows Client"
               Name="Path"
               Type="string"
               Value="[MyAppBaseFolder]MyApp"
               KeyPath="yes" />

或者,您可以在目录树中定义“MyApp”并直接引用它。这看起来有点像添加以下作为MyAppBaseFolderINSTALLFOLDER的同行)的孩子:

 <Directory Id='MyAppFolder' Name='MyApp' />

然后将RegistryValue元素更新为:

<RegistryValue Root="HKLM"
               Key="SOFTWARE\MyApp ID\MyApp ID Windows Client"
               Name="Path"
               Type="string"
               Value="[MyAppFolder]"
               KeyPath="yes" />

我更喜欢后者,但这只是因为我更喜欢使用标识符而不连接字符串。