Making installation packages with WiX (1)

Source: Internet
Author: User


Download the latest version of WiX toolset and install download

The version after Wix toolset V3.5 has been integrated into Visual Studio, where we can write code directly in VS and compile with vs.


First open Visual Studio, and then choose Create WiX Setup Project. After the creation is complete, in the project we can see a Product.wxs file named, the code is as follows:

<?xml version= "1.0" encoding= "UTF-8"?><Wix xmlns="Http://">    <Product Id="*" Name= "SetupProject1" Language=" 1033 " Version=" " manufacturer="" UpgradeCode=  "8E1EFB05-1E12-40E5-ABCA-C8BD7965BF2A">        < package installerversion=" compressed" = "yes" installscope="Permachine" />        <majorupgrade downgradeerrormessage="A newer version of [ProductName] is already Installed. " />        <mediatemplate />        <Feature Id="Productfeature" Title="SetupProject1"  level ="1">            <componentgroupref Id="productcomponents" />        </Feature>    </Product>    <Fragment>        <Directory Id="TARGETDIR" Name="SourceDir">            <Directory Id="ProgramFilesFolder">                <Directory Id="Installfolder" Name="SetupProject1" />            </Directory>        </Directory>    </Fragment>    <Fragment>        <componentgroup Id= "productcomponents" Directory=" Installfolder ">            <!--Todo:remove The comments around this Component element and the componentref below in order to add resources To this installer. -            <!--<component id= "Productcomponent" > -                <!--todo:insert files, registry keys, and other resources here.            <!--</Component> --        </componentgroup>    </Fragment></Wix>

Property Description:

1. UpgradeCode 标签中的 UpgradeCode 是产品的版本 是该产品当前版本的id3.4.5.6. Manufacturer 公司或者组织名称

After the project is created, we need to add files to the installation package. WiX adds a file in a convenient way, and <File Source="文件路径" /> you can add a file to the installation package by using it directly. 文件路径it can be represented by absolute paths and relative paths, and variables may be required for relative paths in WiX. For example:

$(var.ReferencedProjectName.TargetDir) 表示项目中引用的另一项目‘ReferencedProjectName‘的输出路径$(env.WIXPATH) 表示系统的环境变量WIXPATH所指向的路径。关于其它的表示方法请大家参阅官网。

Here we add a folder to the project resource and add one under this folder TextFile1.txt , and then add the following code below the comment in the code above //todo

<Component Id="ProductComponent" Guid="7B428173-1277-482B-BC2E-CC008F3B79F9">    <File Source="resource/TextFile1.txt" /></Component>

Then after the specification is Manufacturer compiled, the compilation succeeds, after the installation, you c:/programfiles(X86)/SetupProject1 can see the files in the directory TextFile1.txt . Just such a simple installation package will make a success. But this simple installation package definitely does not meet our daily work needs. Below I will show you how to implement some additional operations


Customize the installation directory structure. Modify the directory structure directories as follows

<Fragment>    <Directory Id="TARGETDIR" Name="SourceDir" <directory< /c6> Id="ProgramFilesFolder">            <Directory Id="Installfolder" Name="SetupProject1" >                <Directory id="Log" name="Log"/>                <Directory id="Data " name="Data"/>            </Directory>        </Directory>    </Directory>    </Fragment>

Then recompile the installation. You will find that the directory structure after installation has become the following

    -ProgramFiles(x86)    --SetupProject1    ---log    ---data

WiX provides us with five UI types by default. About the style of each UI. Please try or view the documentation yourself.

    1. wixui_advanced Dialog Set
    2. Wixui_featuretree Dialog Set
    3. Wixui_minimal Dialog Set
    4. Wixui_mondo Dialog Set
    5. Wixui Dialogs

If we want to refer to any UI, we just need to product.wxs add the following code to the file

<UIRef id="WixUI_Advanced"/>

Then compile and run, and you'll see that the UI has changed. If you need a custom UI then you need to rewrite a UI and add it to WixUI_Advanced the UI sequence. ( Please see next article)


WIX allows us to customize the action. If you need to customize the custom Action, we need to create another C# Custom Action Project project of type. After the creation succeeds, add one to the project CustomAction.cs and then edit the code as follows:

using  system;using  System.Collections.Generic; using  System.Text; using  Microsoft.deployment.windowsinstaller;namespace customaction1{public  class  customactions {[CustomAction] public  static  ActionResult customaction1  (Session session) {session.            Log ( "Begin CustomAction1" ); return         actionresult.success; }    }}

Such a custom method is defined. Then compile the project. After the project compiles successfully, there will be two output files and. The file that ends up is the CustomAction.dll CustomAction.CA.dll one CA.dll we need. We then add the CustomAction project to a reference to the project that was created earlier. Then add the file customAction.wxs and add the following code

<?xml version= "1.0" encoding= "UTF-8"?><Wix xmlns="Http://">    <Fragment>    <Binary Id="Binaryfile" sourcefile="$ (var.) Customaction.targetdir) CustomAction1.CA.dll " />    <CustomAction Id="CustomAction1" binarykey="Binaryfile"  Dllentry="CustomAction1" />    </Fragment></Wix>

Such a customaction is created and introduced successfully. Now we can call this method. In WiX, the action is executed in sequence. If we are going to add a custom event, we have to specify what event it executes before or after, see the following code, and the sequence of events for WiX, please refer to the sequence of events

<InstallExecuteSequence>    <Custom Action="CustomAction1" After="InstallFiles"/>  </InstallExecuteSequence>

The code above specifies to InstallFiles execute immediately after the method execution is complete CustomAction1 . In this way, a custom method is defined successfully and is successfully called.

With custom CustomAction, we can do some custom actions. Like writing log files or whatever.

Next I'll show you how to make a custom interface using WiX and add a custom interface to the UI sequence

Making installation packages with WiX (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.