【问题标题】:Wix Toolset - how to install a file to a completely different directory and not as a root subdirectory?Wix 工具集 - 如何将文件安装到完全不同的目录而不是作为根子目录?
【发布时间】:2020-07-27 13:26:31
【问题描述】:

对于我的应用程序,大部分文件需要安装到 ProgramFiles 的目录中,另外一个文件需要安装在 AppData/Local 的目录中。

这是我目前所拥有的一个例子:

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="Folder1" />
        </Directory>
    </Directory>
</Fragment>

  
<Fragment>
    <ComponentGroup Id="AppID" Directory="INSTALLFOLDER">
        <Component Id="AppID">
             <File Source="$(var.myApp.TargetPath)" />
        </Component>
        <Component Id="OtherFile" Guid="INSERT-GUID_HERE">
            <File Id='OtherFile' Name='OtherFile' Source="otherfile" KeyPath='yes' />
        </Component>
        <Component Id="CopyId">
            <CopyFile Id="CopyId" FileId="OtherFile" 
                    DestinationDirectory="LocalAppDataFolder" />
        </Component>
</Fragment>

我尝试将另一个文件复制到 AppData/Local,但这不会编译并给出错误:

Unresolved reference to symbol 'Directory:LocalAppDataFolder' in section 'Fragment:'

理想情况下,我希望其他文件位于 AppData/Local 的目录中,而不是 ProgramFiles 中。

【问题讨论】:

  • 您得到的编译错误是因为您的 Directory XML 节点中没有对目标目录的引用。

标签: windows wix windows-installer


【解决方案1】:

应用程序启动:考虑在应用程序启动时进行文件复制,而不是作为设置的一部分。更容易根据需要实施、调试和更改。


修复:尝试直接在 TARGETDIR 元素下添加它。这可确保标准目录 LocalAppDataFolder 是已编译 MSI 文件的目录表的一部分:

<Directory Id="LocalAppDataFolder" Name="AppData">

或者,这里有一个更大的模型:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="INSTALLFOLDER" Name="SetupProject2" />
  </Directory>
  <Directory Id="LocalAppDataFolder" Name="AppData">
    <Directory Id="AppRootDirectory" Name="MyApplication">
      <Component Id="Test" Feature="ProductFeature" Guid="{11111111-1111-1111-1111-A73067A1AE95}">
        <RemoveFolder Id="AppRootDirectory" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\Something" Name="Flag" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </Directory>
  </Directory>
</Directory>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多