【问题标题】:Copy file to arbitrary directory in Wix?将文件复制到Wix中的任意目录?
【发布时间】:2021-10-01 12:55:30
【问题描述】:

这是一个真正的新手问题,但我已经阅读了所有的 Wix 介绍和 Wix 食谱,但我显然错过了他们所有人都假设的一些重要背景。

我想将单个文件(Microsoft Word 模板)安装到用户的 Word STARTUP 模板目录 (C:\Users\AppData\Roaming\STARTUP)。我还没有找到这样的 Wix 示例。这是我的尝试:

 <Directory Id="TARGETDIR" Name="SourceDir">
     <Directory Id="AppDataFolder"> 
        <Directory Id="A1" Name="Microsoft">
            <Directory Id="A2" Name="Templates">
                <Directory Id="StartupTemplates" Name="STARTUP">
 </Directory></Directory></Directory></Directory></Directory>
  
  <DirectoryRef Id="StartupTemplates">
    <Component Id="ApplicationFiles" Guid="0E4812A6-AEC3-4B36-8654-E4FAA6XXXXXX">
        <File Id="TheTemplate" Source="ImageAndTableSupport.dotm"/>
        <RemoveFolder Id="DeleteTheTemplate" Directory="StartupTemplates" On="uninstall"/>
    </Component>
 </DirectoryRef>

  <Feature Id="DefaultFeature" Level="1">
     <ComponentRef Id="ApplicationFiles"/>
  </Feature>

我收到很多错误:

error LGHT0204 : ICE38: Component ApplicationFiles installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file.
error LGHT0204 : ICE64: The directory A2 is in the user profile but is not listed in the RemoveFile table.
error LGHT0204 : ICE64: The directory A1 is in the user profile but is not listed in the RemoveFile table.

另外,它不起作用。安装提示需要管理员权限,并且似乎在某处复制了某些内容,但我找不到它。 :)

我应该如何在 Wix 上编写这个操作?

【问题讨论】:

    标签: installation wix


    【解决方案1】:

    啊,我终于明白了,经过几个小时的头撞。原来 Wix 是关于设置配置变量的。所以这行:

     <Directory Id='FRED'>
    

    其实就是'安装在配置变量FRED对应的文件夹里面'

    此外,如果 Microsoft Installer 无法执行操作,它似乎并不介意。它只是默默地失败。所以,如果你的道路是错误的(就像我的一样),那就艰难了。

    这是工作代码(省略标准媒体、产品和包装符文):

        <SetDirectory Id="STARTUP_TEMPLATES" Value="[AppDataFolder]\Microsoft\Word\STARTUP" />
        
        <Directory Id="TARGETDIR" Name="SourceDir"> <!-- Required by Wix -->
            <Directory Id="STARTUP_TEMPLATES">
                <Component Id="ApplicationFiles" Guid="0E4812A6-AEC3-4B36-8654-E4FAAXXXXXX" KeyPath="yes" >
                    <File Id="TheTemplate" Source="ImageAndTableSupport.dotm" Vital="yes" />
                </Component>
            </Directory>
        </Directory>
    
        <Feature Id="DefaultFeature" Level="1">
            <ComponentRef Id="ApplicationFiles"/>
        </Feature>
    

    完整的实现,包括升级支持(不是微不足道的)是here。 Windows 甚至会在卸载过程中检查 Word 是否正在使用该文件!如果您重复使用它,请确保更改 UUID!

    【讨论】:

    • 最好编辑您的 GUID,这样没有人有机会克隆它。
    • 谢谢,但我做到了,@ChristopherPainter - 这就是 XXX。但在 GitHub 上真正实现会更加困难。这就是我发表评论的原因。
    • 对不起,我没有读完所有的字符。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 2021-06-16
    相关资源
    最近更新 更多