如何将 ui 中 WiX Msi 安装路径的默认值设置为 Program Files?

问题描述:

我创建了一个 WiX 安装程序 MSI.当我运行 msi 时,在 UI 中要求安装路径.目前它加载包含大部分可用空间的驱动器.如何将其设置为始终位于程序文件文件夹中?我尝试了下面的行,但没有用.

I have created a WiX installer MSI. When i run the msi, the installation path is asked for in the UI. Currently it loads the drive containing most of the free space. How can I set it to be at program files folder all the time? I tried the below line but it didn't work.

 <Property Id="WIXUI_INSTALLDIR" Value="C:\\Program Files\" />

以下是我为上述元素得到的错误.

Below is the error I get for the above element.

 The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2343. The arguments are: , , 

如何让 UI 始终加载 C:\Program Files 作为默认位置?任何帮助将不胜感激.

How can I make the UI load C:\Program Files as the default location all the time? Any help would be much appreciated.

你想利用已经定义好的 windows installer 属性,它们总是由 Windows Installer 定义(注意某些 64 位的属性).在这种情况下,特别是 ProgramFilesFolder

You want to make use of the already defined windows installer properties which are always defined by Windows Installer (caveat on some 64-bit only properties). In this case specifically the ProgramFilesFolder

尝试使用这样的目录定义:

Try using a directory definition like this:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="MyProductFolder" />
            </Directory>
        </Directory>
    </Fragment>
</Wix>

然后,遵循与这个关于 的快速教程页面相同的原则使用 WixUI_InstallDir

And then, following the same principal as this quick tutorial page about using WixUI_InstallDir

你会想做

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

现在,当您显示允许您更改安装位置的 UI 页面时,它的值应为 C:\Program File\MyProductFolder

Now when you show the UI page that lets you change the install location it should have the value C:\Program File\MyProductFolder

作为旁注,我会避免将安装位置 设为 C:\Program Files,因为这可能会导致您将大量无关文件添加到该位置,而不是将它们包含在该位置在产品/程序文件夹中.

As a side-note, I would avoid making the install location just C:\Program Files because that may cause you to add a ton of extraneous files to this location where they should instead be contained in a product/program folder.

你也不应该尝试硬编码像C:\Program Files\"这样的路径.在这种特定情况下,我可以给你两个简单的例子,为什么不这样做.不能保证用户使用 C:\ 驱动器作为他们的主驱动器,甚至根本使用 C:\ 驱动器(此轶事 此处).另一个问题是(对于 32 位安装)在 32 位机器上,您希望安装到 Program Files 位置,但在 64 位机器上,您希望安装到Program Files (x86)"位置.

You should also never try to hardcode a path like "C:\Program Files\". In this specific case I can give you two quick examples why not to. There is no guarantee that the user is using the C:\ drive as their main drive or even uses a C:\ drive at all (one anecdote of this here). Another issue is (for 32-bit installs) on a 32-bit machine you'll want to install into the Program Files location but on a 64-bit machine you'll want to install into the "Program Files (x86)" location.