zoukankan      html  css  js  c++  java
  • Wix 打包工具

    0 序言

      前一段时间微软禁止使用盗版软件,于是把Visual Studio、Office及Installshield等盗版软件卸载了,换上了免费的版本。VS有免费的社区版,Office有WPS可代替,唯独 Installshield 没有找到合适的替代者(个人用惯了Installshield所以不考虑nsis等),于是把目光转向Wix工具集

      Wix(Windows Installer XML)是微软提供的一套免费的打包工具集,功能十分强大,但是体验不太好——需要自己编写 Product.wxs 文件。用户需要阅读Wix的xml文件规范,然后根据个人需要添加相应的模块到Product.wxs文件中。

      对于程序开发者而言阅读文档不是难事,难就难在要不厌其烦的做同样的事情。就拿添加文件来举例:wxs文件中,添加文件需要经历三步:

    第一步,创建文件目录结构

    
    
    <!-- Step 1: Define the directory structure -->
    <DirectoryId="TARGETDIR"Name="SourceDir">
        <DirectoryId="ProgramFilesFolder">
            <DirectoryId="APPLICATIONROOTDIRECTORY"Name="My Application Name"/>
        </Directory>
    </Directory>

    第二步,添加文件到目录中

    <!-- Step 2: Add files to your installer package -->
    <DirectoryRef Id="APPLICATIONROOTDIRECTORY">
        <Component Id="myapplication.exe" Guid="PUT-GUID-HERE">
            <File Id="myapplication.exe" Source="MySourceFilesMyApplication.exe" KeyPath="yes" Checksum="yes"/>
        </Component>
        <Component Id="documentation.html" Guid="PUT-GUID-HERE">
            <File Id="documentation.html" Source="MySourceFilesdocumentation.html" KeyPath="yes"/>
        </Component>
    </DirectoryRef>

    第三部,告知wix安装

    <!-- Step 3: Tell WiX to install the files -->
    <Feature Id="MainApplication" Title="Main Application" Level="1">
        <ComponentRef Id="myapplication.exe" />
        <ComponentRef Id="documentation.html" />
    </Feature>

      由此可见,如果要添加多个文件,工作量可想而知。为此有一个国外的开发者专门编写了一套开源的WixEdit的软件,该软件提供了一套UI供用户编辑与编译wxs文件,但是后来他觉得编写这个软件花费了他太多的时间(大概是6个月的样子),因此没有维护了。我个人也下载了这个软件,总体下来体验不太好,主要有以下几点:

    首先,对最新的Wix 3.x工具集支持不是很好。WixEdit 使用的是老的wix格式;

    其次,软件操作有些繁琐。添加文件时,容易卡死。且没有提供模板修改文件属性,用户需要对每个文件的属性进行编辑;

    最后,需要编辑的地方太多。对于紧需要基本模块的用户而言不太友好。

      当然,WixEidt的功能还是很完善的,Wix文档里边描述的模块几乎都可以通过UI操作添加到wxs文件中。但个人不太喜欢用这种功能全但体验不好的软件,于是决定自己编写一款简单的wxs文件编辑器软件——WixFileEditor。

    1 WixFileEditor 软件简介

      WixFileEditor 是一款针对Wix setup工程文件 Product.wxs 的编辑器,其只提供简单的编辑功能,不提供编译功能(编译需要在Visual Studio IDE中完成)。

      WixFileEditor包含三大模块:产品、文件与安装,软件自动添加快捷方式、注册表信息及卸载操作功能代码。考虑到简单性原则,本软件只提供基本的打包工作,用户若要使用安装界面设置等高级功能,可自行对Product.wxs文件进行修改以满足各自的需求。

      下面对软件进行一个简单的介绍,详细介绍可参见软件的用户手册(下载软件后的帮助文档):

    1.1 产品信息

      产品信息提供了产品名称、版本、公司、ID及平台的编辑,如图1所示。

                    图1 WixFileEditor软件的产品模块

    1.2 文件

      文件提供 ProgramFilesFolder、AppDataFolder、PersonalFolder、CommonAppDataFolder、CommonFilesFolder及LocalAppDataFolder 6个系统目录,用户可以往里边添加安装文件与文件夹。

                     图2 WixFileEditor软件文件模块

    1.3 安装

      添加完文件(包含可执行文件与图标)后,在“安装”标签页的“可执行文件”与“图标”组合框中选择相应的文件名,还可以勾选“安装后运行”复选框实现当软件安装完毕后运行的效果。

                       图3 WixFileEditor 安装模块

       当完成以上3部后,点击保存就完成了Product.wxs文件的编辑工作,可以利用Visual Studio 工具编译生成安装包了,是不是很简单呢。

    WixFileEditor 生成的Product.wxs文件模板如下:

    <?xml version="1.0"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
        <Product Id="5385DB4F-662F-4E88-95D5-F0664F59BD88" Name="MyProduct" Codepage="1252" Language="2052" Version="1.0.0" Manufacturer="MyCompany" UpgradeCode="0A657DFC-BBDA-46D6-B225-EFBD13F00EA8">
            <!-- <?Abbreviation ?> -->
            <Package Keywords="Installer" Platform="x86" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
            <MajorUpgrade DowngradeErrorMessage="A newer version of MyProduct is already installed." />
            <MediaTemplate EmbedCab="yes" />
            <Feature Id="ProductFeature" Title="MyProduct_setup" Level="1">
                <ComponentGroupRef Id="ProductComponents" />
            </Feature>
            <Icon Id="WINDOWS.ICO" SourceFile="E:workspaceWixFileEditorin
    esourcesiconswix.ico" />
            <Property Id="ARPPRODUCTICON" Value="WINDOWS.ICO" />
            <Property Id="WIXUI_INSTALLDIR" Value="WIX_0" />
            <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" />
            <UI>
                <UIRef Id="WixUI_InstallDir" />
                <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
            </UI>
            <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="运行 MyProduct" />
            <Property Id="WixShellExecTarget" Value="[#WIX_1]" />
            <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" />
        </Product>
        <Fragment>
            <Directory Id="TARGETDIR" Name="SourceDir">
                <Directory Id="ProgramFilesFolder">
                    <Directory Id="WIX_3" Name="MyCompany">
                        <Directory Id="WIX_0" Name="MyProduct">
                            <Directory Id="WIX_4" Name="resources">
                                <Directory Id="WIX_5" Name="doc" />
                                <Directory Id="WIX_7" Name="icons" />
                                <Directory Id="WIX_9" Name="images" />
                                <Directory Id="WIX_11" Name="internat">
                                    <Directory Id="WIX_12" Name="zh_CN" />
                                </Directory>
                            </Directory>
                        </Directory>
                    </Directory>
                </Directory>
                <Directory Id="ProgramMenuFolder">
                    <Directory Id="ApplicationProgramsFolder" Name="MyProduct" />
                </Directory>
                <Directory Id="DesktopFolder" Name="Desktop" />
            </Directory>
        </Fragment>
        <Fragment>
            <ComponentGroup Id="ProductComponents">
                <Component Id="WIX_6" Directory="WIX_5" Guid="EA78BFE3-0E37-4220-BF59-E484EC39E6FA">
                    <File Id="WIX_6" Source="E:workspaceWixFileEditorin
    esourcesdochelp.chm" ProcessorArchitecture="x86" KeyPath="yes" />
                </Component>
                <Component Id="WIX_8" Directory="WIX_7" Guid="3D126CBA-840B-411B-BD55-516EA95B49A0">
                    <File Id="WIX_8" Source="E:workspaceWixFileEditorin
    esourcesiconswix.ico" ProcessorArchitecture="x86" KeyPath="yes" />
                </Component>
                <Component Id="WIX_10" Directory="WIX_9" Guid="82A12587-0630-4BF7-8C0F-4EDE928AF083">
                    <File Id="WIX_10" Source="E:workspaceWixFileEditorin
    esourcesimageswix.bmp" ProcessorArchitecture="x86" KeyPath="yes" />
                </Component>
                <Component Id="WIX_13" Directory="WIX_12" Guid="574FDF31-CEED-4CE7-AC10-896B19449904">
                    <File Id="WIX_13" Source="E:workspaceWixFileEditorin
    esourcesinternatzh_CNWixFileEditor.mo" ProcessorArchitecture="x86" KeyPath="yes" />
                </Component>
                <Component Id="WIX_1" Directory="WIX_0" Guid="2EC6FF4C-ECC2-4F01-BF1F-6D5473788A51">
                    <File Id="WIX_1" Source="E:workspaceWixFileEditorinWixFileEditor.exe" ProcessorArchitecture="x86" KeyPath="yes" />
                </Component>
                <Component Id="ApplicationShortcut" Directory="ApplicationProgramsFolder" Guid="05CA50FE-E71F-4C69-B0B7-171F4932EF51">
                    <Shortcut Id="ApplicationStartMenuShortcut" Name="MyProduct" Description="MyProduct is a dispensing software" Target="[#WIX_1]" WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                    <Shortcut Id="UninstallProduct" Name="卸载 MyProduct" Target="[SystemFolder]msiexec.exe" Arguments="/x [ProductCode]" Description="MyProduct" />
                    <Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="MyProduct" Target="[#WIX_1]" WorkingDirectory="APPLICATIONROOTDIRECTORY" />
                    <RemoveFolder Id="CleanUpShortCut" Directory="ApplicationProgramsFolder" On="uninstall" />
                    <RegistryValue Root="HKCU" Key="SoftwareMyProduct" Name="installed" Type="integer" Value="1" KeyPath="yes" />
                </Component>
            </ComponentGroup>
        </Fragment>
    </Wix>
    Product.wxs

    软件的下载地址:https://download.csdn.net/download/lyyanziyu/14968464

  • 相关阅读:
    oracle中新建用户和赋予权限
    Oracle创建表空间和表
    IntelliJ IDEA 使用教程(2019图文版) -- 从入门到上瘾
    idea
    oracle
    JavaScript常见调试方法
    java
    css -html-文档流
    Ubuntu18.04安装常用软件指南
    java实现点击查询数据生成excel文件并下载
  • 原文地址:https://www.cnblogs.com/ziyu-trip/p/14163012.html
Copyright © 2011-2022 走看看