首页 > 解决方案 > WiX:在组件传输期间保留递归目录结构

问题描述

Wix 3.11.2 和 Visual Studio Community 2019 在这里。我的项目具有以下目录结构:

...\Source\Repos\my-app-setup\
  my-app-setup\
    bin\
    obj\
    testo\
      fizz\
        abc\
          def\
            ghi\
              abba.txt
      buzz\
        bar.txt
      foo.txt
    my-app.exe
    my-app-setup.wixproj
    my-app-setup.wxs
  my-app-setup.sln

我的my-app-setup.wxs文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">​
  <Product Id="*" Name="MyApp" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="1e540666-dda2-4cbe-91b7-ac9525d96c86">​
    <Package Description="MyApp tool" Compressed="yes" />​
    ​
    <MediaTemplate EmbedCab="yes"/>​
    ​
    <Directory Id="TARGETDIR" Name="SourceDir">​
      <Directory Id="ProgramFilesFolder">​
        <Directory Id="INSTALLFOLDER" Name="MyApp" />​
      </Directory>​
    ​
      <Directory Id="DesktopFolder" Name="Desktop">​
        <Component Id="ApplicationShortcutDesktop" Guid="*">​
          <Shortcut Id="ApplicationDesktopShortcut"​
            Name="MyApp"​
            Description="Shortcut for MyApp"​
            Target="[INSTALLFOLDER]my-app.exe"​
            WorkingDirectory="INSTALLFOLDER"/>​
          <RemoveFolder Id="DesktopFolder" On="uninstall"/>​
          <RegistryValue​
            Root="HKCU"​
            Key="Software/MyApp"​
            Name="installed"​
            Type="integer"​
            Value="1"​
            KeyPath="yes"/>​
        </Component>​
      </Directory>​
    </Directory>​
    ​
    <Component Id="FooTxtComponent" Directory="INSTALLFOLDER">​
      <File Source="testo/foo.txt" />​
    </Component>​
    ​
    <Component Id="AbbaComponent" Directory="INSTALLFOLDER">​
      <File Source="testo/fizz/abc/def/ghi/abba.txt" />​
    </Component>​
    ​
    <Component Id="ExecutableComponent" Directory="INSTALLFOLDER">​
      <File Source="my-app.exe" />​
    </Component>​

    <Feature Id="MainFeature" Title="MyApp" Level="1">​
      <ComponentRef Id="FooTxtComponent" />​
      <ComponentRef Id="AbbaComponent" />​
      <ComponentRef Id="ExecutableComponent" />
      ​
      <ComponentRef Id="ApplicationShortcutDesktop" />​
    </Feature>​
  </Product>​
</Wix>

所以它基本上只是将一堆文件从项目复制到C:\Program Files (x86)\MyApp目录中,然后在桌面上创建一个快捷方式(到 EXE)。简单的东西。

当我构建它并运行 MSI 时,生成的C:\Program Files (x86)\MyApp目录如下所示:

C:\Program Files (x86)\
  MyApp\
    foo.txt
    abba.txt
    my-app.exe

所以 WiX 只是提取我​​指定的文件并将它们放入MyApp目录中,与 EXE 文件处于同一级别。我想要这个;我想保留与我的 VS 项目中存在的相同的递归目录结构。因此,我希望 WiX MSI 生成而不是上面的:

C:\Program Files (x86)\
  MyApp\
    testo\
      fizz\
        abc\
          def\
            ghi\
              abba.txt
      foo.txt
    my-app.exe

完成此任务的最简单方法是什么?

谢谢!

标签: visual-studiowixwindows-installer

解决方案


您需要嵌套此示例中所示的文件夹(朝向底部):https ://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with

插图:

<Directory Id="TARGETDIR" Name="SourceDir">
   <Directory Id="ProgramFilesFolder">
      <Directory Id="INSTALLDIR" Name="Example">
         <Component>
              <File Source="example.exe"/>
         </Component>
      </Directory>
   </Directory>
</Directory>

也许还检查:


推荐阅读