WiX: How to automatically include localized satellite assemblies?

强颜欢笑 提交于 2019-12-04 14:02:00

You can use HarvestDirectory task to automatically collect files to be included in installer. You just need to point it to folder with your satellite assemblies and on each build of installer - target folder will be rescanned and file list will be regenerated.

For example:

1) Place in .wixproj harvest task inside beforedBuild target (it will be commented by default)

<Target Name="BeforeBuild">
<HeatDirectory OutputFile="SatelliteAsm_Files.wxs" Directory="$(SolutionDir)PathToYourAssemblies" DirectoryRefId="MODULELOCATION" ComponentGroupName="Modules" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" PreprocessorVariable="var.ApplicationModuleDir" SuppressUniqueIds="True" />

2) Build your installer first time. After that you will find SatelliteAsm_Files.wxs file inside your WIX project. It will have structure similar to this:

<Fragment>
    <DirectoryRef Id="DIRVARIABLE">
        <Directory Id="dir8B97956DEA791D69AB336941C9163652" Name="x64">
            <Component Id="cmpE72E1056FC8A2AE97260E772A6386763" Guid="{481FF1F3-7AFF-4C17-9AE0-5347BEEB3726}">
                <File Id="filACCD137532BB3AE1F4B3BC207018585B" KeyPath="yes" Source="$(var.ApplicationLibDir)\x64\name.txt" />
            </Component>
            ...
<Fragment>
    <ComponentGroup Id="GroupName">
        <ComponentRef Id="cmpE72E1056FC8A2AE97260E772A6386763" />
        ...

3) Add it as link (it's important you don't want source control to set this file to read only, coz WIX will fail on build) to your project.

4)Reference this ComponentGroup in any of your features

 <Feature Id="MyFeauture">
    <ComponentGroupRef Id="GroupName" />

Finally it's ready! Now files collected from folder you specified in harvest task will be included in your installer. But don't expect this to work out of box because it's royal pain to setup this and you may need to try different combinations of task keys or even XSD transformations to leave only needed files (yes WIX can do XSD transforms, and no there is no easy and agile way to filter files or folder harvested by WIX)

Note: you can use it not only for satellite assemblies - it's ok to harvest entire bin, 3rd party libs or whatever you want, so you don't need to update installer project by hand every time you add new assembly to your solution.

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