WiX Packaging Series (i) How to use WiX to create the installer

Source: Internet
Author: User
Tags comments guid generator guid identifier pack parent directory

Http://www.xuebuyuan.com/1798879.html

Recently, due to the project needs, the need to create the installation program for customers, the first use of VS2005 to pack the package, but for some time found that vs packaging is too rigid, and use a lot of problems. Charges of commercial packaging tools are not in my mind, so found WiX on the Internet, a little understanding of the next, found that WiX really can meet my needs, but the online WiX Chinese information is poor, Baidu, Google on the search for WiX Chinese information is poor, some simple applications, Not enough to meet my requirements, no way, only on their own, fortunately the project is not very urgent, so began to spend time slowly familiar with WiX. Familiar with the road, found that using WiX is also a big project, so I will use the WiX process of some of the major issues are recorded, for myself and everyone to refer to:

1.1 Installing WiX

First, we need to download a WiX installation file online, download address: http://wix.sourceforge.net/, here we download the version is WiX v3.0 released, all of the following sample programs are running under this version.

WiX is written in C #, and before you install WiX, you must install the. NET Framework 2.0 and

Service Pack 1, which is required for the WiX toolset to run, does not mean that the NET Framework run environment is required on the machine where the application is installed, depending on the development language environment that your application uses. Using WiX, you can never package. NET applications, or you can package Java applications and other language-developed applications.

Before we start using WiX, we need to download the sample source code, which comes from the WiX
tutorial, each of the examples in the WiX tutorial in detail, e-text good can look first, you will find that there are some parts of the WiX tutorial is difficult to understand, perhaps because of the knowledge of some MSI SDK, it is not explained in detail, I am also new to WiX and MSI soon, there may be some concepts in the article to understand the inaccuracy of the place. This article is my experience in learning and using WiX, considering that WiX beginners will try to introduce them in more detail at the beginning.

about 1.2 WiX

WiX is the abbreviation for Microsoft Windows Installer XML, and WiX's source code is written using an XML file, which is then preprocessed, compiled, and linked to create a Windows Installer database. We can use the WiX toolset on the command line or use MSBuild to compile and link the WiX source code, and if we install WiX before we have installed visual Studio (VS2005 or VS2008, It is said that VS2010 has integrated wix3.0), you can also build the installation project in the visual Studio IDE environment.

Here we discuss the command-line approach using the WiX toolset, and in the seventh chapter we will refer to how to use the two most common commands used in the VS environment, namely candle and light, candle is used to compile the WiX source files, Wix;wix. Light is used to link the compiled intermediate file generation MSI installation package. To understand their role, let's see how WiX generates the installation package.

1.3 Generating the Samplefirst sample installation package

Let's start by understanding their usage, find Samplefirst in the sample source code, To open samplefirst.wxs with VS or another text editor and replace each yourguid-xxxx-xxxx-xxxx-xxxxxxxxxxxx with a unique GUID identifier, we can use the VS-band GUID generator in VS Under the Tools menu , select Create GUID, and you must ensure that each GUID is unique (note that the GUID can be either curly braces or without curly braces). Then we can compile, and it's best to c:/program before compiling.
Files/windows Installer XML V3/bin directory is set to the system's environment variable path, so that we can execute commands in any directory, at the command prompt, we execute the following command to compile:

Candle.exe Samplefirst.wxs

After successful execution, the Samplefirst.wixobj file is generated in the current directory and then we execute the light command:

Light.exe Samplefirst.wixobj

After the light command executes successfully, we can see the generated installation file Samplefirst.msi, so that a simple MSI installation package was created successfully.

1.4 Samplefirst Code

The samplefirst sample shows the most basic WiX app, and if you want to build a richer installation package, you must also know how to write WiX code; The WiX source code is the standard XML markup language, and we open Samplefirst. Wxs file to see the composition of the Code:

<Product> tags are basic information about the products we publish, language and codepage are the locales in which we build our installation packages, and we'll talk about the configuration of localized languages in later chapters ; name and manufacturer are well understood; It is important to note the ID and UpgradeCode properties, which are GUID numbers with unique identities, and the Version property, which is the release number of the released product (not including the revision number).

The ID of the <Package> tag is also the GUID number that uniquely identifies, the difference is that we need a different GUID for each build of the installation package, so this is set to *, and the compiler will automatically generate a GUID for it each time it is compiled. , we will elaborate on the role of these properties in the process of making the upgrade and update packages. The Description property is the full name or description of the installation package, comments can be interpreted as annotations, it is optional, and installerversion specifies the windows that are required to run the installation package
Installer minimum version; compressed specifies whether to compress the files in the installation package, generally we are set to Yes, you can save a lot of space.

<Media> TagsSet the file storage method,Cabinetis the name of the compressed package that must be used in conjunction with the compressed property of the packages, if not setCabinetAndEmbedcabproperty, the compressed must be set to No;EmbedcabDetermines whether the compressed package is embedded in the installation file (. msi), and if the installed files are much larger, we can define multipleMedia, compressing different files to differentMediaIn<Property>Tags we can be seen as a static variable, its value is its property of value, the general PropertyWe can change and use the value of the custom action during the installation process, and we'll introduce it later.<Directory>Tags include all the content to be installed, including applications, shortcuts, dynamic link libraries, documents, registry information, etc.;<Directory>Nesting represents the directory structure of the installer: about the top-levelDirectory, which contains a predefined identifier "TARGETDIR", and its name is also a predefined value "SourceDir"; TARGETDIR is allDirectoryThe parent directory of the directory, which must contain one and only one TARGETDIR in each package installation
Directory。 On the second floor.DirectoryThe identifier is ProgramFilesFolder, which is also a predefined identity that specifies the default installation directory of the software under the Program Files directory of the system disk;

The

    third layer is our custom directory , which, by default, is on its upper level directory ( ProgramFilesFolder
) generates a custom directory named the value of the Name property;     Bottom directory The identifier is INSTALLDIR, which is also our custom, according to our definition, by default the program will be installed in the following directory: System drive:/program Files/acme/foobar 1.0/ The InstallDir property value is the absolute path to the installation file, and by default its value depends on the directory structure we define, and if we change the installation path during installation, the value of the InstallDir property will change, and it will not depend on the directory structure we define. It will depend on the installation path we choose.          It's important to note that installdir and ProgramFilesFolder are Directory identifier, in fact all of the Directory identifiers We define can be considered as property   Properties , while ProgramFilesFolder is a property   attribute that comes with Windows Installer, Windows Installer
sets its value at startup; , Windows Installer also sets the value of installdir, or it can be referenced elsewhere, even if you do not explicitly define a installdir
property . (For a list of properties provided by Windows Installer, you can find it in the MSI SDK document, reference property Reference From which we can see that the following ProgramMenuFolder and Desktopfolder are all properties that are already provided by Windows
Installer. )

In addition , the default InstallDir value for directory is calculated automatically based on the directory structure, if we want to install some files in a fixed location, such as the e-packing directory, we need to explicitly define a property, The property's value attribute is the location where the directory is to be stored. You can try to add the following code under Fragment , what will happen:

<property Id = "INSTALLDIR" value= "e:/"/>
ProgramMenuFolder
DirectoryThe shortcut that is installed in the program, Start menu, is defined in. < component>The label defines all the elements to be installed, and its child elements can be file, Shortcut (shortcut), Removefolder, Registryvalue (registry key)And so on, a ComponentCan contain multiple child elements, but must have one and only one element of keypath= ' yes '
<Feature>The label is the part that defines the installation, we can put the different use of the installation files into the feature part, and then during the installation process to customize the installation of different parts, about FeatureSpecific features and parts customization in the 2nd chapter introduces the user interface in detail; < icon>The icon file for the label definition, which is the icon in the application execution file, or it can be a separate icon file. 1.5 Optimized Sample codeIn order to increase the readability of the source file, I will samplefirst the source file to do some optimization, against Samplefirst, let us see what changes:

<?xml version= ' 1.0 ' encoding= ' windows-1252 '?>   
<wix xmlns= ' Http://schemas.microsoft.com/wix/2006/wi ' >   
    <product name= ' Foobar 1.0 ' id= ' {2c9a3180-95f0-4cdd-b02c-a0abcaae3413} ' upgradecode= ' { f4f8195e-e907-42dd-bb90-cc2403fa7384} '   
      Language= ' 1033 ' codepage= ' 1252 ' version= ' $ (var. Version) ' manufacturer= ' Acme Ltd ' >   
    
        <package id= ' * ' keywords= ' Installer ' description= ' Acme ' s Foobar 1.0 Installer '   
          Comments= ' Foobar is a registered trademark of Acme Ltd. ' manufacturer= ' Acme Ltd '   
          installerversion= ' languages= ' 1033 ' compressed= ' yes ' summarycodepage= ' 1252 '/>   
   
         <media Id

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: info-contact@alibabacloud.com 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.