简体   繁体   English

Wix 修复安装在默认路径中,而不是安装应用程序的位置

[英]Wix repair installs in default path, not where the app is installed

I have this property:我有这个属性:

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/>

My directories:我的目录:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LocalAppDataFolder">
    <Directory Id="LocalAppDataCompany" Name="Company">
      <Directory Id="INSTALLFOLDER" Name="Product" />
    </Directory>
  </Directory>
</Directory>

And it compiles successfully.它编译成功。 When I run the .msi, it installs the files in C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product as expected.当我运行 .msi 时,它会按预期将文件安装在C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product中。

But the problem is:但问题是:

  1. I run the installer and change the path (let's say in the dialog, i changed the path to Product2我运行安装程序并更改路径(假设在对话框中,我将路径更改为Product2
  2. The product is installed in ...\\AppData\\Local\\Company\\Product2 successfully产品安装成功在...\\AppData\\Local\\Company\\Product2
  3. I run the installer again, and chose repair我再次运行安装程序,并选择修复
  4. Now I have 2 instance of product:现在我有 2 个产品实例:

C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product C:\\Users\\[CurrentUser]\\AppData\\Local\\Company\\Product2

How can I fix the repair, to reinstall files (during repair) in the ...\\AppData\\Local\\Company\\Product2 (or wherever the app is installed originally)?如何修复修复,重新安装文件(修复期间) ...\\AppData\\Local\\Company\\Product2 (或最初安装应用程序的任何地方)?

I have tried using registry search (since I am saving the value of INSTALLFOLDER in the registry), but it is not working.我曾尝试使用注册表搜索(因为我将INSTALLFOLDER的值INSTALLFOLDER在注册表中),但它不起作用。

EDIT: Wow I really need to read the complete question before answering.编辑:哇,我真的需要在回答之前阅读完整的问题。 Just noticed you were storing this value in the registry.刚刚注意到您将此值存储在注册表中。 I'll still leave my answer as is though since it might be useful.我仍然会保留我的答案,因为它可能有用。


You'll need to implement a remember me pattern so that your install can pickup properties that may have been modified during the initial install.您需要实现记住我的模式,以便您的安装可以选择在初始安装期间可能已修改的属性。 The install dir is probably the most frequently modified property that you should remember.安装目录可能是您应该记住的最常修改的属性。 There are a lot of installers that don't do this right and you'll notice if you are upgrading they always default to the default install dir not where you previously installed which can be annoying.有很多安装程序没有正确执行此操作,您会注意到,如果您要升级它们,它们总是默认为默认安装目录,而不是您以前安装的位置,这可能很烦人。

This explains rather well the concept of the "remember me" pattern. 很好地解释了“记住我”模式的概念。 You can get away with the simple implementation in the majority of cases.在大多数情况下,您可以使用简单的实现。

The gist is that you need to store the value of the altered install dir (generally in the registry) and then try to pick it up every time you run the installer subsequently.要点是您需要存储更改的安装目录的值(通常在注册表中),然后每次运行安装程序时尝试获取它。

For the INSTALLFOLDER property you'll want to just add two things, a registry search and a registry key.对于 INSTALLFOLDER 属性,您只需添加两件事,一个注册表搜索和一个注册表项。

First we need to add a new component with a registrykey to write the INSTALLFOLDER's value to the registry首先,我们需要添加一个带有注册表项的新组件,以将 INSTALLFOLDER 的值写入注册表

<Component Id="InstallFolderRegistry" Directory='INSTALLFOLDER'>
  <RegistryValue Root='HKCU' Key='SOFTWARE\[Manufacturer]\[ProductName]'
                 Name='InstallFolder' Value='[INSTALLFOLDER]'
                 Type='string' KeyPath="yes" />    
</Component>

You can also piggyback this registry value into another component if you wish just remove "KeyPath="yes"".如果您只想删除“KeyPath="yes"”,您也可以将此注册表值附加到另一个组件中。

This will put the value of the INSTALLFOLDER property in the registry during install time.这将在安装期间将 INSTALLFOLDER 属性的值放入注册表中。

Now we need to try and read this value if it exists on startup so that during upgrades or during repairs we will get the right location the user chose to install.现在我们需要尝试读取这个值,如果它在启动时存在,以便在升级或修复期间我们将获得用户选择安装的正确位置。

<Property Id='INSTALLFOLDER'>
  <RegistrySearch Id='InstallFolderRegSearch' Root='HKCU'
                  Key='SOFTWARE\[Manufacturer]\[ProductName]'
                  Name='InstallFolder' Type='raw' />
</Property>

Now when you repair the installer should find this registry key and then repair the correct directory.现在,当您修复安装程序时,应该找到此注册表项,然后修复正确的目录。 Also during upgrades, the install location will be set to the same location as the currently installed product.同样在升级期间,安装位置将设置为与当前安装的产品相同的位置。

To note, if you have a non-static ProductName or Manufacturer you can just put in static text instead of "[Manufacturer]" and "[ProductName]" in the registry path.请注意,如果您有一个非静态的 ProductName 或 Manufacturer,您可以在注册表路径中输入静态文本而不是“[Manufacturer]”和“[ProductName]”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM