There has been a lot of demand for a way to easily author simple variations on a single component template very quickly.  The need for such a solution is evident if you’ve ever wanted to create a single component in multiple language versions or for multiple platforms and found yourself try to get it working in the preprocessor or manually authoring all the variations.  Here is a proposal for how I believe this could be done with a preprocessor extension which I’m currently calling WixPivotsExtension™ J

 

Desired result:

    <Fragment>

        <DirectoryRef Id="TARGETDIR">

                <Component Id="MyComponent.x86.en_us" Guid="{22B5A745-4784-407c-9D76-DAA07495993C}" Win64=”no”>

                    <File Id="File1.x86.en_us" Name="test.txt" Source="SourceDir\x86\en_us\test.txt" KeyPath="yes" />

                    <File Id="File2.x86.en_us" Name="test2.txt" Source="SourceDir\x86\en_us\test2.txt" />

                    <RegistryValue Root="HKLM" Key="Software\MyProduct" Name="en_us" Value="1" Type="integer" />

                </Component>

            </Directory>

    </Fragment>

 

    <Fragment>

        <DirectoryRef Id="TARGETDIR">

                <Component Id="MyComponent.x86.he_il" Guid="{6ABEA558-276D-4aa1-AADC-D6D415431154}" Win64=”no”>

                    <File Id="File1.x86.he_il" Name="test.txt" Source="SourceDir\x86\he_il\test.txt" KeyPath="yes" />

                    <File Id="File2.x86.he_il" Name="test2.txt" Source="SourceDir\x86\he_il\test2.txt" />

                    <RegistryValue Root="HKLM" Key="Software\MyProduct" Name="he_il" Value="1" Type="integer" />

                </Component>

            </Directory>

    </Fragment>

 

    <Fragment>

        <DirectoryRef Id="TARGETDIR">

                <Component Id="MyComponent.x64.en_us" Guid="{4BBD4239-19CC-4792-8738-D196929367D3}" Win64=”yes”>

                    <File Id="File1.x64.en_us" Name="test.txt" Source="SourceDir\x64\en_us\test.txt" KeyPath="yes" />

                    <File Id="File2.x64.en_us" Name="test2.txt" Source="SourceDir\x64\en_us\test2.txt" />

                    <RegistryValue Root="HKLM" Key="Software\MyProduct" Name="en_us" Value="1" Type="integer" />

                </Component>

            </Directory>

    </Fragment>

 

    <Fragment>

        <DirectoryRef Id="TARGETDIR">

                <Component Id="MyComponent.x64.he_il" Guid="{CE2D5AAC-CD05-4fee-B310-9522E6F6615F}" Win64=”yes”>

                    <File Id="File1.x64.he_il" Name="test.txt" Source="SourceDir\x64\he_il\test.txt" KeyPath="yes" />

                    <File Id="File2.x64.he_il" Name="test2.txt" Source="SourceDir\x64\he_il\test2.txt" />

                    <RegistryValue Root="HKLM" Key="Software\MyProduct" Name="he_il" Value="1" Type="integer" />

                </Component>

            </Directory>

    </Fragment>

 

 

Here’s what the template might look like (MyComponent.wxs):

<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

 

    <?foreach pivot in MyComponentPivots.xml?>

    <Fragment>

        <DirectoryRef Id="TARGETDIR">

                <Component Id="MyComponent.$(var.Pivot.Suffix)" Guid="$(var.Pivot.Guid)" Win64="$(var.Pivot.Win64)">

                    <File Id="File1.$(var.Pivot.Suffix)" Name="test.txt" Source="$(var.Pivot.FilePrefix)\test.txt" KeyPath="yes" />

                    <File Id="File2.$(var.Pivot.Suffix)" Name="test2.txt" Source="$(var.Pivot.FilePrefix)\test2.txt" />

                    <RegistryValue Root="HKLM" Key="Software\MyProduct" Name="$(var.Pivot.Culture)" Value="1" Type="integer" />

                </Component>

            </Directory>

    </Fragment>

    <?endforeach?>

 

</Wix>

 

And here’s how the values are specified (MyComponentPivots.xml):

<?xml version="1.0" encoding="UTF-8"?>

<Pivots Suffix=".$(var.Pivot.Platform).$(var.Pivot.Culture)" FilePrefix="SourceDir\$(var.Pivot.Platform)\$(var.Pivot.Culture)">

    <Pivot Platform="x86" Win64="no">

        <Pivot Culture="en_us" Guid="{22B5A745-4784-407c-9D76-DAA07495993C}" />

        <Pivot Culture="he_il" Guid="{6ABEA558-276D-4aa1-AADC-D6D415431154}" />

    <Pivot>

    <Pivot Platform="x64" Win64="yes">

        <Pivot Culture="en_us" Guid="{4BBD4239-19CC-4792-8738-D196929367D3}" />

        <Pivot Culture="he_il" Guid="{CE2D5AAC-CD05-4fee-B310-9522E6F6615F}" />

    <Pivot>

</Pivots>

 

 

So basically, there would be a preprocessor extension that runs before the normal WiX preprocessor and expands out the foreach statement into different views on the component using the various pivots from the xml file.

 

Here’s the details of how it would work:

  1. Find <?foreach?> statements and their corresponding pivots.xml files.
  2. For each leaf node in the pivots.xml file, create a view of the Fragment inside the <?foreach?>.  (In the example above, there are 4 leaf nodes and thus 4 views on the component).
  3. Traverse the xml from the document element down to the leaf node turning all the attributes encountered along the way into preprocessor variables (those which are set multiple times will be overridden by the children – so inheritance is possible).
  4. All variables are set with “Pivot.” In front of them to avoid collisions with variables that may be specified on the candle command line and via <?define?> statements.  (I’m flexible on whether this is important or not – we could also just set the variables directly which would mean less typing in the WiX source file to use the variables).
  5. Run the normal WiX preprocessor over the now expanded authoring, thus resulting in the desired authoring above.

 

Note that this system is completely flexible in terms of the naming conventions for the variables which are set – you can use whatever names you like.  I’ve used “Platform” and “Culture” but you could use “Processor” and “Language” or whatever else is appropriate for your organization.  You could just have one pivot if language is all that matters of add as many more as you want as necessary.  You can even define meta-variables for suffixes of identifiers and prefixes of file paths.

 

I look forward to hearing your feedback.

 

Thanks,

Derek

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to