New content are available at http://tis-method.org/. All articles from this site will be moved to the new location.

понедельник, 29 ноября 2010 г.

WIX include file generation

When you create an installation of the product you should list all of its components.
This process not only tedious, but also can generate synchronization errors of the project output components and the installation package.

For some products, the composition of components may changing significantly during development.
In such cases, automating the process of creating installation is a must.

WIX installation file description can include additional files using the <?include ?> instruction.
Such mechanism would create the main installation file once, and localize all changes into external files.
So, we need two external files. One to describe the included files, the second to define the components to install.

Installation files sample
Main installation file:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  ...
  <Product Id="$(var.ProductGUID)" Name="$(var.ProductName)" Language="1033" Version="$(var.ProductVersion)" Manufacturer="$(var.CompanyName)" UpgradeCode="$(var.UpgradeCode)">
    ...
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="COMPANYDIR" Name="$(var.CompanyName)">
          <Directory Id="ProductDir" Name="$(var.ProductName)">
            <Directory Id="IncDir" Name="z3d">
              <?include inc1.wxs ?>
            </Directory>
            ...
          </Directory>
        </Directory>
      </Directory>
    </Directory>
    ...
    <Feature Id="ProductFeatures" Title="$(var.ProductName)" Level="1" ConfigurableDirectory="COMPANYDIR">
      <?include inc2.wxs ?>
      ...
    </Feature>
    ...
  </Product>
</Wix>

Enumeration for installing files (inc1.wxs):
<Include>
 <Directory Id="inc_dir1" Name="boost">
  <Component Id="inc_comp1" Guid="{B2B874BA-6480-4F20-9B5A-49F6DB83E830}">
   <File Id="inc_comp1_0" Name="cast.hpp" DiskId="1" Source="b:\prjs\z3d\z3d\boost\cast.hpp"/>
  </Component>
 </Directory>
 ...
</Include>

Enumeration for installing components (inc2.wxs):
<Include>
 <ComponentRef Id="inc_comp1"/>
 ...
</Include>

scan4wix command line parameters
Console utility scan4wix.exe is used for generating wix include files.
--help                    Show this help
  --root arg                Scan root path
  --prefix arg              ID's prefix string
  --regex arg               Regular expression for file content scanning
  --include_dirs arg (=.*)  Include dirs regular expression
  --exclude_dirs arg        Exclude dirs regular expression
  --include_files arg (=.*) Include files regular expression
  --exclude_files arg       Exclude files regular expression
  --out1 arg                Output file name for WIX dir&files list
  --out2 arg                Output file name for WIX features list

Usage example
scan4wix.exe --root="с:\project\bin" --prefix="prj" --exclude_dirs=".svn" --out1="prj1.wxs" --out2="prj2.wxs"

Utility will scan directory structure beginning from "с:\project\bin". Scan will exclude any ".svn" directories.
Output file prj1.wxs will contain all files from the selected directories. Output file prj2.wxs will contain corresponding components list.

Additionally, you can specify regular expression for files content. If you set --regex command line argument, utility will evaluate this regular expression for each input file content. If result of evaluation is true, the file will add into install package, otherwise will skip.

Links
You can find scan4wix utility in the tools folder in the z3d.

Комментариев нет:

Отправить комментарий