Creating Merge Modules
Creating a Merge Module is very much like creating a Windows Installer package. So, let's create a new text file called "module.wxs" and put the standard skeleton in it, as so:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'> </Wix>
Then to create a Merge Module, we add the <Module/> element and add the required attributes:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'> <Module Id='TestModule' Guid='87654321-4321-4321-4321-210987654321' Language='1033' Version='1.0.0.0'> <Package Id='87654321-4321-4321-4321-210987654321' Description='My first Merge Module' Comments='This is my first attempt at creating a Windows Installer Merge Module' Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' /> </Module> </Wix>
You can, if you wish, compile and link that code. You'll get a very small and not very interesting .msm file from light. So, let's add a text file to this Merge Module like we did to the Windows Installer package above. First, create a text file called "readme2.txt" and put a different message to yourself in there. Then, update the source code to include the new file:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'> <Module Id='TestModule' Guid='87654321-4321-4321-4321-210987654321' Language='1033' Version='1.0.0.0'> <Package Id='87654321-4321-4321-4321-210987654321' Description='My first Merge Module' Comments='This is my first attempt at creating a Windows Installer Merge Module' Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' /> <Directory Id='TARGETDIR' Name='SourceDir'> <Directory Id='MyModuleDirectory' Name='.'> <Component Id='MyModuleComponent' Guid='87654321-4321-4321-4321-110987654321'> <File Id='readme2' Name='readme2.txt' src='readme2.txt' /> </Component> </Directory> </Directory> </Module> </Wix>
That's it! You now have a Merge Module that can be shared with other teams to install your "readme2.txt" file. Now that we have a Merge Module, let's actually use it in a Windows Installer package.
Incorporating a Merge Module into a .wxs file
Merge Modules can only be merged into Windows Installer package. Fortunately, we have a .wxs file that creates a Windows Installer package from our first experiments with WiX. So, let's add the two lines (yes, only two lines are necessary) to merge in your new Module. Open your "product.wxs" source file again, and add:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'> <Product Id='12345678-1234-1234-1234-123456789012' Name='Test Package' Language='1033' Version='1.0.0.0' Manufacturer='Microsoft Corporation'> <Package Id='12345678-1234-1234-1234-123456789012' Description='My first Windows Installer package' Comments='This is my first attempt at creating a Windows Installer database' Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' /> <Media Id='1' Cabinet='product.cab' EmbedCab='yes' /> <Directory Id='TARGETDIR' Name='SourceDir'> <Directory Id='ProgramFilesFolder' Name='PFiles'> <Directory Id='MyDir' Name='TestProg' LongName='Test Program'> <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'> <File Id='readme' Name='readme.txt' DiskId='1' src='readme.txt' /> </Component> <Merge Id='MyModule' Language='1033' src='module.msm' DiskId='1' /> </Directory> </Directory> </Directory> <Feature Id='MyFeature' Title='My 1st Feature' Level='1'> <ComponentRef Id='MyComponent' /> <MergeRef Id='MyModule' /> </Feature> </Product> </Wix>
Now when you compile your Windows Installer package source file, it will include the installation logic and files from the Merge Module. The next time you install the "product.msi", you should see two text files in the "Test Program" directory instead of one.