Thứ Tư, 25 tháng 11, 2015

WiX- copy files or directory to install folder

In this post, I will talk about copying some files or directory to install folder.

I. Copy some files to install folder

Example, I have 2 files: readme.txt, config.xml. I will copy these files to the install folder.

1. Add new components that contain the sample files.
In the Product.wxs file, find lines of code that say:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="$(var.AutoClick_FirstBlood.TargetPath)" />
</Component>
</ComponentGroup>
</Fragment>
Replace it with the following lines of code:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="$(var.AutoClick_FirstBlood.TargetPath)" />
</Component>
<Component Id="txtFile_Component" Guid="1A4C52F3-B0D3-40BE-8667-FF534E16C5B7">
<File Id="txtFile_File" Source="C:\FilesToAdd\readme.txt" KeyPath="yes" />
</Component>
<Component Id="xmlFile_Component" Guid="1B27DDFD-8B4E-4E12-874A-DA7E4F3BE3A8">
<File Id="xmlFile_File" Source="C:\FilesToAdd\config.xml" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>

2. Rebuild the WiX project.

II. Copy some directories and files to install folder

Suppose that I have folders, sub-folders and files as below:
  • C:\FilesToAdd\readme.txt
  • C:\FilesToAdd\config\config_common.xml
  • C:\FilesToAdd\config\hotkey\config_hotkey.xml


And now, I will copy them to install folder.

1. Define the directory structure.
In the Product.wxs file, find lines of code that say:
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="AutoClick_FirstBlood" />
</Directory>
Replace it with following lines of code:
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="AutoClick_FirstBlood">
<Directory Id="Config_Folder" Name="config">
<Directory Id="Hotkey_Folder" Name="hotkey" />
</Directory>
</Directory>
</Directory>

2. Add new components that contain the sample files.
In the Product.wxs file, find lines of code that say:
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="$(var.AutoClick_FirstBlood.TargetPath)" />
</Component>
</ComponentGroup>
Replace it with following lines of code:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="$(var.AutoClick_FirstBlood.TargetPath)" />
</Component>
<Component Id="readme_Component" Guid="1A4C52F3-B0D3-40BE-8667-FF534E16C5B7">
<File Id="readme_File" Source="C:\FilesToAdd\readme.txt" KeyPath="yes" />
</Component>
</ComponentGroup>
<DirectoryRef Id="config_Folder">
<Component Id="config_common_Component" Guid="1B27DDFD-8B4E-4E12-874A-DA7E4F3BE3A8">
<File Id="config_common_File"
Source="C:\FilesToAdd\config\config_common.xml" />
</Component>
</DirectoryRef>
<DirectoryRef Id="hotkey_Folder">
<Component Id="config_hotkey_Component" Guid="5A86C120-7C0E-42D5-A357-D75B2E145D4A">
<File Id="config_hotkey_File"
Source="C:\FilesToAdd\config\hotkey\config_hotkey.xml" />
</Component>
</DirectoryRef>
</Fragment>


3. Add componentRef's for config_common file and config_hotkey file.
We need to add componentRef's for config_common file and config_hotkey file under Feature element.
In the Product.wxs file, find lines of code that say:
<Feature Id="ProductFeature" Title="AutoClick_FirstBlood" Level="1"> <ComponentGroupRef Id="ProductComponents" /> <ComponentRef Id="App_Desktop_Shortcut"/> <ComponentRef Id="App_Start_Menu_Shortcut"/></Feature>
Replace it with following lines of code that say:
<Feature Id="ProductFeature" Title="AutoClick_FirstBlood" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="App_Desktop_Shortcut"/>
<ComponentRef Id="App_Start_Menu_Shortcut"/>
<ComponentRef Id="config_common_Component"/>
<ComponentRef Id="config_hotkey_Component"/>
</Feature>

4. Rebuild the WiX project.

1 nhận xét: