IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]使用WIX制作C#应用程序的安装包

    caimouse发表于 2016-05-26 11:48:57
    love 0

    1. 下载安装wix3.9

    从网站: http://wixtoolset.org/releases/  

    2. 安装完成wix,就可以在vs2012里使用了。

    3. 创建项目

    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
      <Product Id="4963AEC3-4CD1-46C3-8986-07F9EB609CB6"
               UpgradeCode="90BDB88B-2213-41FF-9DE9-A5EC3C23D9C1"
               Version="1.0.0.1"
               Codepage="936"
               Language="2052"
               Name="TestCSharp"
               Manufacturer="caiware">
        <Package Id ="{9C55B670-6180-430D-B47E-35C3D2540BF8}" 
                 InstallerVersion="300" Compressed="yes" InstallScope="perMachine"/>
        <Media Id="1" Cabinet="TestCSharp.cab" EmbedCab="yes" />
        <Property Id="WIXUI_INSTALLDIR" Value="TESTCSHARPDIR" />
        <Property Id="QtExecDeferredExample" Value="command line to run"/>
        <Property Id="RemovePreviousVersions" Value='True' />
    
        <!-- 下面是检查.net框架是否安装-->
        <PropertyRef Id="NETFRAMEWORK40FULL"/>
        <PropertyRef Id="NETFRAMEWORK45"/>
    
        <Condition Message='This setup requires Microsoft .NET Framework 4.0 Full package or greater 
                   needs to be installed for this installation to continue.'>
          <![CDATA[Installed OR NETFRAMEWORK40FULL]]>
        </Condition>
        <Condition Message='This setup requires Microsoft .NET Framework 4.5 package or greater needs 
                   to be installed for this installation to continue.'>
          <![CDATA[Installed OR NETFRAMEWORK45]]>
        </Condition>
    
        
        <!-- 下面是在目标目录里创建子目录-->
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="APPLICATIONROOTDIRECTORY" Name="Caiware">
              <Directory Id="TESTCSHARPDIR" Name="TestCSharp">
              </Directory>
            </Directory>
          </Directory>
    
          <!-- 指定快捷方式的目录 -->
          <Directory Id="ProgramMenuFolder">
            <Directory Id="ApplicationProgramsFolder" Name="Caiware">
              <Directory Id="ApplicationFolderTestCSharp" Name="TestCSharp"/>
            </Directory>
          </Directory>
        </Directory>
    
        <!-- Program Files\Caiware\TestCSharp -->
        <DirectoryRef Id="TESTCSHARPDIR">
          <Component Id="TestCS1.exe" Guid="{526A9833-3EE5-429B-90A8-BCCE2566AEE4}">
            <File Id="TestCS1.exe" Source="$(var.SolutionDir)TestCS1.exe" KeyPath="yes" />
          </Component>
        </DirectoryRef>
      
    
    
        <!-- 添加一个快捷方式 -->
        <DirectoryRef Id="ApplicationProgramsFolder">
          <Component Id="ApplicationShortcut" Guid="{A3E0B89B-9958-437E-80F4-4C11EA61CEC9}">
            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" 
                           Key="Software\Microsoft\Caiware" 
                           Name="installed" 
                           Type="integer" 
                           Value="1" 
                           KeyPath="yes"/>
          </Component>
        </DirectoryRef>
        <DirectoryRef Id="ApplicationFolderTestCSharp">
          <Component Id="ApplicationTestShortcut" Guid="{86C887F2-191B-4E2D-9301-795FE8C0E344}">
            <Shortcut Id="UnistTestCSharp"  
                      Name="卸载" 
                      Target="[SystemFolder]msiexec.exe" 
                      Arguments="/x [ProductCode]" 
                      Description="Uninstall"/>
            <RemoveFolder Id="ApplicationFolderTestCSharp" On="uninstall"/>
            <RegistryValue Root="HKCU" 
                           Key="Software\Microsoft\Caiware\TestCSharp" 
                           Name="installed" 
                           Type="integer" 
                           Value="1" 
                           KeyPath="yes"/>
          </Component>
        </DirectoryRef>
    
        <Feature Id="MainApplication" Title="主应用程序" Level="1">
          <!-- Program Files\Caiware\TestCSharp -->
          <ComponentRef Id="TestCS1.exe" />
    
       
          <!-- 指定快捷方式 -->
          <ComponentRef Id="ApplicationShortcut" />
          <ComponentRef Id="ApplicationTestShortcut" />
        </Feature>
    
    
        <WixVariable Id="WixUILicenseRtf" Value="$(var.SolutionDir)License.rtf" />
        <!-- <WixVariable Id="WixUIDialogBmp" Value="$(var.SolutionDir)dialog.bmp" /> -->
        <!-- <WixVariable Id="WixUIBannerBmp" Value="$(var.SolutionDir)banner.bmp" /> -->
    
        <!-- 添加UI到安装文件和从UI上触发运行指定的动作。-->
        <UI>
          <UIRef Id="WixUI_InstallDir" />
        </UI>
    
        <!-- 这里是指定安装之后调用运行程序和卸载时运行的程序 -->
        <InstallExecuteSequence>
          <RemoveExistingProducts After="InstallInitialize" />    
        </InstallExecuteSequence>
    
        <CustomAction Id="QtExecDeferredExample" BinaryKey="WixCA" DllEntry="CAQuietExec"
                Execute="deferred" Return="check" Impersonate="no"/>
    
      </Product>
    </Wix>

    编写上面的文件,就可以生成相应的安装包msi文件。

    可以到这里下载完整的工程文件:

    http://download.csdn.net/detail/caimouse/9531732



    蔡军生  QQ:9073204  深圳



沪ICP备19023445号-2号
友情链接