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:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'> </Wix>
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/2006/wi'> <Module Id='TestModule' Language='1033' Version='1.0.0.0'> <Package Id='PUT-GUID-HERE' Description='My first Merge Module' Comments='This is my first attempt at creating a Windows Installer Merge Module' Manufacturer='Microsoft Corporation' InstallerVersion='200' /> </Module> </Wix>
You can, if you wish, compile and link that code. You will get a very small and not very interesting .msm file from the output of light.exe. So, let's add a text file to this Merge Module as we did to the Windows Installer package. First, create a text file called readme2.txt and put a different message than the message in readme1.txt 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/2006/wi'> <Module Id='TestModule' Language='1033' Version='1.0.0.0'> <Package Id='PUT-GUID-HERE' Description='My first Merge Module' Comments='This is my first attempt at creating a Windows Installer Merge Module' Manufacturer='Microsoft Corporation' InstallerVersion='200' /> <Directory Id='TARGETDIR' Name='SourceDir'> <Directory Id='MyModuleDirectory' Name='.'> <Component Id='MyModuleComponent' Guid='PUT-GUID-HERE'> <File Id='readme2' Name='readme2.txt' Source='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 packages. 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 your new Module. Open your "product.wxs" source file again, and add:
<?xml version='1.0'?> <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'> <Product Id='PUT-GUID-HERE' Name='Test Package' Language='1033' Version='1.0.0.0' Manufacturer='Microsoft Corporation'> <Package 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='Test Program'> <Component Id='MyComponent' Guid='PUT-GUID-HERE'> <File Id='readme' Name='readme.txt' DiskId='1' Source='readme.txt' /> </Component> <Merge Id='MyModule' Language='1033' SourceFile='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.