WiX工具 - 安装程序不会将文件添加到安装目录

时间:2017-02-06 15:21:34

标签: c# wix

我正在使用WiX工具3.10创建一个简单的C#应用​​程序的安装程序。我已经按照官方文档中的教程进行了操作,但是我遇到了以下问题:我需要在应用程序目录中添加.txt文件,但安装程序只会添加应用程序的可执行文件。这是.wxs文件的XML:

目录结构:

<Fragment>
<!-- Step 1: Define the directory structure -->
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="APPLICATIONROOTDIRECTORY" Name="Controllore">
    </Directory>
  </Directory>
</Directory>    
</Fragment>

添加文件:

  <Fragment>
    <!-- Step 2: Add files to your installer package -->
    <DirectoryRef Id="APPLICATIONROOTDIRECTORY">
      <Component Id="Controllore.exe" Guid="ce2f6f3f-73b4-4fa9-9c3f-76685d520fdb">
        <File Id="Controllore.exe" Source="MyPath\Controllore.exe" KeyPath="yes" Checksum="yes"/>
      </Component>
      <Component Id="param.txt" Guid="5ffe84e4-5893-48be-af86-1731bcd176ca">
        <File Id="param.txt" Source="MyPath\param.txt" KeyPath="yes"/>
      </Component>
    </DirectoryRef>
  </Fragment>
  <Fragment>
    <!-- Step 3: Tell WiX to install the files -->
    <Feature Id="MainApplication" Title="Main Application" Level="1">
      <ComponentRef Id="Controllore.exe" />
      <ComponentRef Id="param.txt" />
    </Feature>
  </Fragment>

最后,我必须添加这些行,否则安装程序不会安装任何内容:

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="APPLICATIONROOTDIRECTORY">
  <Component Id="CMP_Controllore">
    <File Source="$(var.Controllore.TargetPath)" KeyPath="yes" />
  </Component>
    </ComponentGroup>
</Fragment> 

2 个答案:

答案 0 :(得分:2)

您需要了解片段未被处理,除非它被另一个片段引用。然后整个片段以原子方式处理。

我有一个名为ISWIX(http://iswix.codeplex.com)的开源项目。它包含VS项目模板和图形设计器,可以帮助您更快地加快速度。然后你可以看看它如何组织它的片段,看看它们是如何组合在一起的,并自己决定如何继续。

这是一段短短2分钟的视频,其中我1)创建桌面应用程序,2)为其创建WiX / IsWiX安装程序。这真的很容易。

https://www.youtube.com/watch?v=nnV_OU6fk8c

答案 1 :(得分:0)

您可以尝试重新排列设置方式。我发现尝试使用片段在学习首次使用WiX时非常令人沮丧。我不知道它是首选的方式,因为大型产品的可维护性会更麻烦,但我有类似的东西(给出你的文件名):

<?xml ...?>
<Wix ...>
  <Product ...>
    <Package ... />
    <MajorUpgrade .../>
    <MediaTemplate EmbedCab="yes" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="APPLICATIONROOTDIRECTORY" Name="Controllore">
          <Component Id="Controllore.exe" Guid="ce2f6f3f-73b4-4fa9-9c3f-76685d520fdb">
            <File Id="Controllore.exe" Source="$(var.Controllore.TargetPath)" 
                    KeyPath="yes" Checksum="yes"/>
          </Component>
          <Component Id="param.txt" Guid="5ffe84e4-5893-48be-af86-1731bcd176ca">
            <File Id="param.txt" Source="$(var.Controllore.TargetDir)param.txt" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>
    <Feature Id="MainApplication" Title="Main Application" Level="1">
      <ComponentRef Id="Controllore.exe" />
      <ComponentRef Id="param.txt" />
    </Feature>
  </Product>
</Wix>

对于较小的项目,我发现将所有相关信息直接放入目录更容易,而不用担心碎片。显然,如果你必须在一个拥有大型项目的团队中工作,这是不合理的。