用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中添加自定義操作部分,因項目沒用上也沒研究。