zoukankan      html  css  js  c++  java
  • WIX 学习笔记

    程序员们都非常熟悉 Hello World!,基本上所有的语言书都以打印一个 Hello World! 作为第一个代码示例。

    我们也要发扬代码界的优良传统,使用 Hello WIX! 作为我们的入门示例。这里对所有的东西都不会做深入的讲解。

    该示例包含两个项目,一个HelloWIX 的 Console 项目负责在控制台上打印 “Hello WIX!”。

    一个HelloWIXInstaller 安装程序, 生成的 MSI 文件执行后, Console 程序安装到机器上并且可以在系统的控制面板中的Programs and Features 中查看 。

    在VS 中新建一个项目 HelloWIXInstaller 负责生成安装文件(MSI)。

    打开VS-> File -> Add -> New Project -> Windows Installer XML -> Setup Project.

                           

    HelloWIXInstaller 项目创建后,打开项目,发现有一个文件名称为 Product.wxs,双击打开文件,可以发现文件为 XML 格式文件,我们主要通过编辑此文件来控制生成的 Windows 安装包。

     

    Ok,万事俱备只欠东风。我们开始编码吧!GO! GO! GO!

    1)      打开HelloWIX Console 程序,写一句 Console.WriteLine(“Hello WIX!”); 然后再写一句Console.Read();。

    2)      打开HellowWIXInstaller 程序,点击 Reference -> 点击 Projects Tab, 选中HelloWIX 项目 -> 点击 Add -> 点击 OK.

     

    3)      双击打开Product.wxs, 弹出一个 XML 编辑界面,找到Product 节点,最重要的节点代表了你要部署,安装的产品。

    为 Id 属性赋值为一个Guid 值。可以使用 PowerShell 的生成一个 Guid 值。

     

    修改 产品名 Name 属性为 HelloWIX。

     Manfacturer 为你们公司的名字,这里我们使用 WIX。

    Version 产品版本号,推荐使用 主版本号.副版本号.Build 号的格式。

      <Product Id="f3fe33a3-0f52-407e-8d4e-5e489b9b18f3" Name="HelloWIX" Language="1033" Version="1.0.0.0"
               Manufacturer="WIX" UpgradeCode="fee9086b-6f65-4ccb-9854-d4fbe5877258">
    View Code

    4)      找到 Fragment 节点,然后找到 Id 为 INSTALLDIR 的 Directory 节点将其名称改为 HelloWIX。这个设置的是安装目录的名称。ProgramFilesFolder 是WIX 中预定义的的变量,指代目标机器上的 Program Files 目录。

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="HelloWIX" />
          </Directory>
        </Directory>
      </Fragment>
    View Code

    5) 找到CommponentGroup 节点, 添加属性 Id, Directory 属性并赋值。添加Component 节点, Component 节点下添加 File 节点。其中$(var.HelloWIX.TargetDir) 表示的 HelloWIX 项目的 binDebug 或者 binRelease 编译文件夹。

    代码如下:

    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="HelloWIXConsole" Guid="03a6e62a-25f7-4ea5-a08f-218dd2d1f689">
            <File Id="HelloWIXEXE" Name="HelloWIX.exe" Source="$(var.HelloWIX.TargetDir)" KeyPath="yes"></File>
          </Component>
    
          <!-- 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>
    View Code

    6)      编译WIX 项目 HelloWIXInstaller

    7)      打开 binDebug 的目录,可以发现生成了一个 msi,一个  cab 和 wixpdb 文件。

    *.msi 文件为安装文件

    *.cab 文件为资源压缩文件

    *.wixpdb 为WIX 项目调试文件

     

    8)      双击 msi 文件运行,等待运行结束打开文件夹 “C:Program Files (x86)” 或者“C:Program Files”, 查找 HelloWIX 文件夹,双击打开 HelloWIX 文件,发现下面有一个 HelloWIX.exe 文件,运行之。我们期待已久的界面就出来了—千呼万唤始出来呀!

     

    9)      打开控制面板,打开 Programs And Features , 可以发现 有一个程序 HelloWIX。右击可以卸载 HelloWIX 程序。

     

    通过以上步骤可以看出,WIX 帮助程序员解决了生成 MSI 安装包的复杂编码过程,仅仅通过 XML 配置,即声明的方式就可以。

    相信大家在做这个实验的过程发现了, 基本上所有WIX的节点都需要 Id 属性来唯一标识一个节点,推荐程序员们在开始自己的 WIX 代码编写之前先设定Id 命名规则,否则你会因 Id 重复而伤痛脑筋的!同时我们也碰到了陌生的Component, Directory, File 等重要节点,具体什么含义,且看下回分解。

    为了保证大家都能做出这个实验,特把 wxs 的配置文件奉上:

    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    
      <Product Id="f3fe33a3-0f52-407e-8d4e-5e489b9b18f3" Name="HelloWIX" Language="1033" Version="1.0.0.0"
               Manufacturer="WIX" UpgradeCode="fee9086b-6f65-4ccb-9854-d4fbe5877258">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />
        <Feature Id="ProductFeature" Title="HelloWIXInstaller" Level="1">
          <ComponentGroupRef Id="ProductComponents" />
        </Feature>
      </Product>
    
      <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="HelloWIX" />
          </Directory>
        </Directory>
      </Fragment>
    
      <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="HelloWIXConsole" Guid="03a6e62a-25f7-4ea5-a08f-218dd2d1f689">
            <File Id="HelloWIXEXE" Name="HelloWIX.exe" Source="$(var.HelloWIX.TargetDir)" KeyPath="yes"></File>
          </Component>
    
          <!-- 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>
    View Code
  • 相关阅读:
    洛谷P3406 海底高铁[差分 贪心]
    POJ3398Perfect Service[树形DP 树的最大独立集变形]
    POJ3928Ping pong[树状数组 仿逆序对]
    UVALive
    UVALive
    http协议进阶(二)URL与资源
    http协议进阶(一)HTTP概述
    http协议基础(十)实体首部字段
    http协议基础(九)响应首部字段
    http协议基础(八)请求首部字段
  • 原文地址:https://www.cnblogs.com/xinghuayang/p/3291502.html
Copyright © 2011-2022 走看看