zoukankan      html  css  js  c++  java
  • Wix 安装部署(一)同MSBuild 自动生成打包文件 转

    原文地址:http://www.cnblogs.com/stoneniqiu/p/3355086.html

    因为项目需要,最近在研究Wix打包部署,园子里也有一些关于wix的博客,方方面面,讲的点各不同。我自己也在测试过程中,写下过程,以供参考。最新版本WiX Toolset v3.7,如何安装的就不说了,可以参考 http://blog.csdn.net/rryqsh/article/details/8274832  

          打包关心的问题有 1).Net版本检查  2)桌面和菜单栏的快捷方式 3)更换图标画面,进度条  4)自动打包  5)自动更新版本。6)安装目录和细节 带着问题去探索,欢迎补充。先走通一个简单的Demo,再回头看概念。

    第一个Wix set Up

        1.先创建一个简单的Winform程序

        

     2. 在解决方案中右键添加新项目,选择Windows Installer XML(前提你要安装了wix Toolset v3.7),再选择Setup Project,修改项目名称,确定。

        

      这样子,解决方案下面会多一个Setup07的工程,这个工程下面有一个Product.wxs 文件,默认已经打开,这是一个XML文件,也就是工程的配置文件,初次看上去各种元素不知所云,先不管,先需要修改三个地方,首先需要引入MyApplication,

    在第三行有一个Product元素,需要在Manfacturer中加入你或者你公司的名字。

    <Product Id="*" Name="Setup07" Language="1033" Version="1.0.0.0" Manufacturer="RJStone" UpgradeCode="3486eddf-0957-45cf-8c26-3de8bceca2b4">

    再在最下方有一个Fragment元素块,修改为

     添加了这么一段

    <Component Id="ProductComponent">
            <File Source="$(var.MyApplication.TargetPath)" />
          </Component>

     完成之后,生成一下,这样第一个简单的wix打包文件已经在SetUp07的bin/debug下面生成了。

     

    点击Setup07.msi 就可以安装了。 但这个时候的安装很快,因为比较简单不会有什么进度条,上一步下一步的,安装完成之后桌面和菜单栏中都没有图标,因为你还没有配置让它有。但在c盘下的Rrogram Files(X86)下面可以找到Setup07这个文件夹,打开他里面就是Myapplication的exe。可以执行。

    还有一个问题就是,只要改变一次这个Myapplication ,重新生成,那么打包文件也会自动生成一个新的,如果你没有改变,只是重复点生成,打包文件是不会更新的。这其实就是借助了MSBuild的机制,自动生成打包文件。当然这个程序的卸载目前就去控制面板中手动卸载吧。

    初步认识Wix

       1)MSBuild 是 Microsoft Build Engine 的缩写,代表 Microsoft 和 Visual Studio 的新的生成平台,引入了一种基于xml的文件格式。他负责生成exe文件,需要生成打包文件需要wix, MSBuild 园子知识库的简解 http://kb.cnblogs.com/page/45681/  

    wix官方文档说:用Msbulid生成wix,需要创建一个.wixproj 的文件,其实这个文件上面的Setup07中VS已经帮我们自动生成,只是要打开文件夹才能看到。

    复制代码
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
        <ProductVersion>3.7</ProductVersion>
        <ProjectGuid>384a3edb-dbda-4948-9071-ae6a05968f55</ProjectGuid>
        <SchemaVersion>2.0</SchemaVersion>
        <OutputName>Setup07</OutputName>
        <OutputType>Package</OutputType>
        <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)MicrosoftWiXv3.xWix.targets</WixTargetsPath>
        <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)MicrosoftWiXv3.xWix.targets</WixTargetsPath>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
        <OutputPath>bin$(Configuration)</OutputPath>
        <IntermediateOutputPath>obj$(Configuration)</IntermediateOutputPath>
        <DefineConstants>Debug</DefineConstants>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
        <OutputPath>bin$(Configuration)</OutputPath>
        <IntermediateOutputPath>obj$(Configuration)</IntermediateOutputPath>
      </PropertyGroup>
      <ItemGroup>
        <Compile Include="Product.wxs" />
      </ItemGroup>
      <ItemGroup>
        <ProjectReference Include="..MyApplicationMyApplication.csproj">
          <Name>MyApplication</Name>
          <Project>{b16ec091-efc7-4cd3-b62b-eec13303d72a}</Project>
          <Private>True</Private>
          <DoNotHarvest>True</DoNotHarvest>
          <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
          <RefTargetDir>INSTALLFOLDER</RefTargetDir>
        </ProjectReference>
      </ItemGroup>
      <Import Project="$(WixTargetsPath)" />
      <!--
        To modify your build process, add your task inside one of the targets below and uncomment it.
        Other similar extension points exist, see Wix.targets.
        <Target Name="BeforeBuild">
        </Target>
        <Target Name="AfterBuild">
        </Target>
        -->
    </Project>
    复制代码

       2)XML文档元素

         Wix本身就是基于XML,因此定义了很多特定的元素,刚开始一看,因为不熟悉容易搞晕。 先也只是初步认识,深入了解还是需要后面的不断测试。不全面的可以去看官方的文档。

        * Product 的父级只有wix,主要由Id,Language,等属性

         Id:产品的GUID,GUID可以借助VS-->工具--->创建GUID 会有五种格式来供选择,这里用4,5,6。不要括号。

         Codepage:指所在地区的代码页,用来进行区域区分

         Language:指所在地区使用的语言,为数字编号,

         Manufacturer:制作厂商

         Name:产品名称

         UpgradeCode:产品更新的GUID

         Version:版本号

       下来列举几个常见的区域代号:
    语言 语言-国家 Language Codepage
    English en-us 1033 1252
    Simplified Chinese zh-cn 2052 936
    Traditional Chinese zh-tw 1028 950

          *Package 记录一些安装包的信息

           InstallerVersion:安装此安装包需要的最小Windows Installer版本,用Windows Installer的主要版本乘以100 加上Window Installer的次要版本。 比如 “200” 代表的是Windows Installer2.0,而405代表的是Windows Installer4.5.

          Compressed: 这个为Yes 表示在源文件中含有压缩文件,对于Merge Module这个属性不必设置。反正为 NoType.

          InstallPrivileges:字面意思为安装优先级,有limited 和 elevated两种 后者是默认值,

          InstallScope: 值为枚举类型,字面意思为安装范围,值必须是perMachine 或者 perUser. 看文档不知道确切的用处,先放过。

         *MajorUpgrade 这个元素支持防止降级

         AllowDowngrades:即回到低版本,如果设置为No(默认值) 会被阻止,这个时候DowngradeErrorMessage 属性必须设置,以给出提示。

         DowngradeErrorMessage:当你安装一个低版本的安装包时会给出的提示。  

         *Feature  一个特性表,特性是可安装的最小单元。 子元素中的ComponentGroupRef 是和 ComponentGroup对应的。前者相当于一个安装目录,后者记录了安装文件的具体位置。

         Id:是唯一的

        Title:就是个短的说明。

        Level:安装的等级,值为0 会使这个特性无效,默认值为1 

        Absent:这个属性定义User是否有权在用户接口中去选择使某个特性不安装(absent),值为allow或者disallow之一

        *Fragment  元素是在wix中创建一个安装数据库的基础块(msi文件就是个数据库),定义之后,是不可改变的(目前不太理解....ORZ)。它的子元素中含有*Ref的元素必须有对应的单元,比如在Fragment中含有两个Component元素,那么 你必须在Feature中用ComponentRef 与Component对应. 默认生成的文档中含有两个Fragment块。 一个包含的是Directory,一个包含的是ComponentGroup ,前者指的是安装目录,后者顾名思义就是Component的一个集合。 

        

    复制代码
    <Fragment>
            <Directory Id="TARGETDIR" Name="SourceDir">
                <Directory Id="ProgramFilesFolder">
                    <Directory Id="INSTALLFOLDER" Name="Setup07" />
                </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 Id="ProductComponent">
            <File Source="$(var.MyApplication.TargetPath)" />
          </Component>
        </ComponentGroup>
        </Fragment>
    复制代码

        *Directory 产品的安装目录。第一个Directory Id=TARGETDIR 是根目录,每一个wix工程都会有这个目录元素,第二个Id=ProgramFilesFolder 对应的就是C:Program Files ,64位的就在x86下,第三个元素就是我们自己的应用程序所在的文件夹,最终形成就是c:Program FilesMy Application Name  在默认的提示中 也可以看见在Component 中添加安装文件,资源,注册表等。这里可以看见最里面的Directory的Id=INSTALLFOLDER是和第二个Fragment中的ComponentGroup的Directory属性是一致的。在Component中就是每一个你需要安装的单元以及它的位置。

    $(var.MyApplication.TargetPath)是wix引用变量。见下表。当然vs2010只是当前版本的意思。

    Variable name

    Example usage

    Example value

    var.ProjectName.Configuration

    $(var.MyProject.Configuration)

    Debug or Release

    var.ProjectName.FullConfiguration

    $(var.MyProject.FullConfiguration)

    Debug|AnyCPU

    var.ProjectName.Platform

    $(var.MyProject.Platform)

    AnyCPU, Win32, x64 or ia64

    var.ProjectName.ProjectDir

    $(var.MyProject.ProjectDir)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMyProject

    var.ProjectName.ProjectExt

    $(var.MyProject.ProjectExt)

    .csproj

    var.ProjectName.ProjectFileName

    $(var.MyProject.ProjectFileName)

    MyProject.csproj

    var.ProjectName.ProjectName

    $(var.MyProject.ProjectName)

    MyProject

    var.ProjectName.ProjectPath

    $(var.MyProject.ProjectPath)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMyProjectMyApp.csproj

    var.ProjectName.TargetDir

    $(var.MyProject.TargetDir)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMyProjectinDebug

    var.ProjectName.TargetExt

    $(var.MyProject.TargetExt)

    .exe

    var.ProjectName.TargetFileName

    $(var.MyProject.TargetFileName)

    MyProject.exe

    var.ProjectName.TargetName

    $(var.MyProject.TargetName)

    MyProject

    var.ProjectName.TargetPath

    $(var.MyProject.TargetPath)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMyProjectinDebugMyProject.exe

    var.ProjectName.Culture.TargetPath

    $(var.MyProject.en-US.TargetPath)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMyProjectinDebugen-USMyProject.msm

    var.SolutionDir

    $(var.SolutionDir)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMySolution

    var.SolutionExt

    $(var.SolutionExt)

    .sln

    var.SolutionFileName

    $(var.SolutionFileName)

    MySolution.sln

    var.SolutionName

    $(var.SolutionName)

    MySolution

    var.SolutionPath

    $(var.SolutionPath)

    C:usersmyusernameDocumentsVisual Studio 2010ProjectsMySolutionMySolution.sln

        整体看一下  Directory定义了安装目录,Component定义了组件及位置,Feature定义了组件在安装时的一些特性。Product和package等定义了安装包的信息。所以还是比较语义化的,继续探索。

        以上只是个人小结,难免有所不当,欢迎指正,如果对你有帮助,请帮忙顶一下。:)

  • 相关阅读:
    显示所有销售订单
    从 “香农熵” 到 “告警降噪” ,如何提升告警精度?
    KubeDL 0.4.0 Kubernetes AI 模型版本管理与追踪
    链路分析 K.O “五大经典问题”
    让容器跑得更快:CPU Burst 技术实践
    All in one:如何搭建端到端可观测体系
    【视频特辑】提效神器!如何用Quick BI高效配置员工的用数权限
    一文说清linux system load
    Flow vs Jenkins 实操对比,如何将Java应用快速发布至ECS
    实时数仓Hologres首次走进阿里淘特双11
  • 原文地址:https://www.cnblogs.com/friendwang1001/p/4300796.html
Copyright © 2011-2022 走看看