创建Merge Modules
创建Merge Module与创建Windows Installer package非常相似。让我们先创建一个名为"module.wxs"的文本文件。如下输入标准的框架:
<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
</Wix>
然后创建Merge Module,我们添加<Module/>元素以及所需的属性:
<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/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>
编译和链接这个代码。你将得到一个非常小的.msm文件。让我象前面给Windows Installer package添加代码一样,给Merge Module添加一个文本文件。首先创建一个名为"readme2.txt"的文本文件,并输入一些不同的文字。然后,更新源码来包含这个文件:
<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/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>
现在,你有了一个Merge Module,它可以和其他团队共享来安装你的"readme2.txt"文件。让我们在Windows Installer package实际应用它。
将Merge Module合成到一个 .wxs 文件
Merge Modules只能合并到Windows Installer package。幸运的是,我们有了一个.wxs 文件用来创建Windows Installer package。因此让我们添加2行代码(是的,只有2行)来合并你的新模块。打开"product.wxs",添加:
<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/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='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>
现在当你编译"product.wxs",它将包含来自Merge Module的安装逻辑和文件。当你再次安装"product.msi"时,你应该在"Test Program"目录下看到两个文本文件。