WiX: How do I prevent multiple copies of a bound file being added to an MSI?

一个人想着一个人 提交于 2020-02-04 05:40:48

问题


I have an installer, which links a wixlib. The wixlib installs an executable file to multiple directories.

When I turn on the "Bind files into the library file" for the wixlib (using the -bf switch), lit.exe adds the executable to the wixlib. However, when I link the wixlib in the MSI, the executable is added multiple times to the MSI file, bloating the installer size.

When I turn off "Bind files into the library file", the problem doesn't happen (but obviously, I need to setup the WiX installer project to know where to find the executable, rather than finding inside the wixlib).

With and without the -bf switch, the final MSI files look similar when viewed using orca, so I'm struggling to see why the MSI in the first case needs to including multiple copies.

The wixlib wxs file looks like:

<Fragment>

<ComponentGroup Id="cmpFoo1">
  <ComponentRef Id="cmpFooExe1" />
</ComponentGroup>

<DirectoryRef Id="TARGET_PATH1">
  <Component Id="cmpFooExe1" Guid="*">
    <File Id="filFooExe1" Name="foo.exe" KeyPath="yes" Source="$(var.source_path)\foo.exe" />
  </Component>
</DirectoryRef>

<ComponentGroup Id="cmpFoo2">
  <ComponentRef Id="cmpFooExe2" />
</ComponentGroup>

<DirectoryRef Id="TARGET_PATH2">
  <Component Id="cmpFooExe2" Guid="*">
    <File Id="filFooExe2" Name="foo.exe" KeyPath="yes" Source="$(var.source_path)\foo.exe" />
  </Component>
</DirectoryRef>

<Feature Id="ftFooFeatures" Level="1">
 <ComponentGroupRef Id="cmpFoo1"/>
 <ComponentGroupRef Id="cmpFoo2"/>
</Feature>

</Fragment>

And the installer wxs file like:

<Product Id="MyProduct" Name="ProductName" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="{UpgradeCode_Guid}">
<!-- ...etc... -->

<Directory Id="ROOT_TARGET_PATH" Name="Foo">
  <Directory Id="TARGET_PATH1" Name="Foo1" ComponentGuidGenerationSeed="{Guid1}" />
  <Directory Id="TARGET_PATH2" Name="Foo2" ComponentGuidGenerationSeed="{Guid2}" />
</Directory>

<Feature Id="ftMain" Level="1">
  <FeatureRef Id="ftFooFeatures" />
</Feature>

<!-- ...etc... -->
</Product>

The expectation is that the final installation listing would be something like: c:\foo\foo1\foo.exe c:'foo\foo2\foo.exe

Is there a way to prevent WiX (presumably the linker?) from adding multiple copies of foo.exe to the final MSI file, whilst still binding foo.exe with the wixlib?


回答1:


WiX has a feature called Smart Cabbing. WiX is supposed to automatically do this for you provided that the file elements have the exact same source path attribute.

This has been asked before on StackOverflow but it's too early in the morning to find it. :-) You will probably want to search and find it though because I remember the question being along the lines of "I have the same sourcepath, why isn't it working" Rob Mensching jumped in on the thread but I don't recall what the resolution was.




回答2:


The best thing I can think of to avoid multiple copies of the .exe being put into the installer is to use the CopyFile element.

If you consider copying not only the files you install, but also other files present on the target PC, remember to include RemoveFile element, because such files are not removed by Windows Installer on uninstall.



来源:https://stackoverflow.com/questions/4721266/wix-how-do-i-prevent-multiple-copies-of-a-bound-file-being-added-to-an-msi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!