使用WIX打包客户端程序

用WPF为客户做了个小工具,打包的时候发现VS2012居然没有安装项目了,搜了下才知道现在推荐使用WIX来打包了http://wix.sourceforge.net/,我用的最新3.7的。

研究了下,发现有两个要点要记录下来,一是对简体中文的支持,二是自动安装.net Framework的支持;希望大家用到该工具的时候不要再走我的弯路。

1.对简体中文的支持,在这里http://www.cnblogs.com/wfwup/archive/2009/07/16/1524708.html下载的中文资源包,加入到项目里重新编译就可以了,原作者提供的是3.0的,发现在3.7下一样能用,感谢技术手札提供。

把我的Product.wxs文件和大家分享下:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
  xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
  
  <Product Id="9C505667-71C4-40C7-8B60-2F186920158C" Name="产品名称" Language="2052" Codepage="936" Version="1.0.0.0" Manufacturer="公司名称" UpgradeCode="3b259853-ebce-47cf-aeef-ef4ef089a080">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate/>
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    <UIRef Id="WixUI_InstallDir" />
    <Feature Id="ProductFeature" Title="OfflineViewer" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
      <ComponentGroupRef Id="ShortcutComponents" />
        </Feature>
  </Product>
  
    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="OfflineViewer" />
            </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ShortcutMenuFolder" Name="产品名称" />
      </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' DiskId='1' Guid='6D98C7EE-6EF9-4747-8D03-E7AD0B6122BD'>
        <File Name='CommonConfig.xml' Source="$(var.EIAC.AccountingArchivess.OfflineViewer.TargetDir)" />
        <File Name='EIAC.AccountingArchivess.OfflineViewer.CustomControl.dll' Source="$(var.EIAC.AccountingArchivess.OfflineViewer.TargetDir)" />
        <File Name='Offline.Common.dll' Source="$(var.EIAC.AccountingArchivess.OfflineViewer.TargetDir)" />
        <File Name='EIAC.AccountingArchivess.OfflineViewer.exe' Source="$(var.EIAC.AccountingArchivess.OfflineViewer.TargetDir)" />
      </Component>
      <!-- </Component> -->
        </ComponentGroup>

    <ComponentGroup Id="ShortcutComponents" Directory="ShortcutMenuFolder">
      <Component Id="ApplicationShortcut" Guid="C919F5ED-D2B3-42E8-9F7C-63269274FE79">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="产品名称" Target="[INSTALLFOLDER]EIAC.AccountingArchivess.OfflineViewer.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="ShortcutMenuFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software/公司名称/产品名称" Name="installed" Type="integer" KeyPath="yes" Value="1" />
      </Component>
    </ComponentGroup>
    </Fragment>

  

</Wix>

2.自动安装.net Framework,参考了这篇文章:http://blog.csdn.net/duanzilin/article/details/5982296

用文本编辑器打开项目文件*.wixproj,在Project节点加入如下xml(请大家选择自己需要的.net版本)

 <ItemGroup> 
    <BootstrapperPackage 
Include=".NETFramework,Version=v4.0,Profile=Client"> 
      <Visible>False</Visible> 
      <ProductName>.NET Framework 4.0 Client</ProductName> 
      <Install>True</Install> 
    </BootstrapperPackage> 
</ItemGroup> 

<Target Name="AfterBuild"> 
    <GenerateBootstrapper ApplicationFile="zh-cn\$(TargetFileName)" 
                          ApplicationName="产品名称" 
                          BootstrapperItems="@(BootstrapperPackage)" 
                          ComponentsLocation="Relative" 
                          CopyComponents="True" 
                          OutputPath="$(OutputPath)" 
                          Path="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\"/> 
</Target>

保存,重新编译即可。那个Bootstrapper目录请大家按照自己电脑上的目录结构修改(一般好像都一样的)

Wix中添加自定义操作部分,因项目没用上也没研究。

posted on 2013-01-21 17:09  小庄  阅读(7149)  评论(7编辑  收藏  举报