最近学习了一下wix。以范例做一下总结吧。
<?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <!--右键testBuild项目在applaycationInfo按钮上可以看出版本号--> <?define ProductVersion="!(bind.assemblyVersion.TestBuild)" ?> <!--点击tools-creat GuiD--> <?define GUID_UPGRADE="934513AD-A097-4823-BF3B-C6D94A770204" ?> <Product Id="*" Name="TestBuild" Language="1033" Version="$(var.ProductVersion)" Manufacturer="Microsoft" UpgradeCode="$(var.GUID_UPGRADE)"> <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> <!--<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> <MediaTemplate />--> <!--install and check if it is the new, if so install ,else pop the message--> <!-- Launch conditions--> <Condition Message="A later version of [ProductName] is already installed.">NOT NEWERVERSIONDETECTED</Condition> <!--Remove old version when install new version--> <Upgrade Id="$(var.GUID_UPGRADE)"> <UpgradeVersion Minimum="$(var.ProductVersion)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" /> <UpgradeVersion Minimum="1.0.0.0" Maximum="$(var.ProductVersion)" OnlyDetect="no" Property="OLDERVERSIONBEINGUPGRADED" IncludeMinimum="yes" IncludeMaximum="no" /> </Upgrade> <InstallExecuteSequence> <FindRelatedProducts Before="LaunchConditions" /> <RemoveExistingProducts After="InstallValidate" /> </InstallExecuteSequence> <!--把.cab集成到.msi中--> <Media Id="1" Cabinet="TestBuild.cab" EmbedCab="yes" /> <!-- Pre-requirement Check .NetFramework4.0 need reference WixNetFixExtension--> <PropertyRef Id="NETFRAMEWORK40FULL"/> <Condition Message="This application requires .NET Framework 4.0. Please install the .NET Framework then run this installer again."> <![CDATA[Installed OR NETFRAMEWORK40FULL]]> </Condition> <Feature Id="ProductFeature" Title="TestBuild" Level="1"> <ComponentGroupRef Id="ProductComponents" /> <ComponentRef Id="ApplicationShortCut"/> <ComponentRef Id="ProductComponent"/> <ComponentRef Id="RemoveFiles"/> </Feature> <!--Install UI guide--> <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" /> <!--after install to run--> <Property Id="WIXUI_EXITDIALOGOPTIONALTEXT" Value="Thank you for installing this product." /> <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch TestBuild now! " /> <!--[#TestBuild] is exe file ‘s ID 在下文--> <Property Id="WixShellExecTarget" Value="[#TestBuild]" /> <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" /> <!--Add UI to your installer publish 用来触发安装之后的启动--> <UI> <UIRef Id="WixUI_InstallDir" /> <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> </UI> <WixVariable Id="WixUILicenseRtf" Value="license.rtf" /> </Product> <Fragment> <!--文件目录,有的是系统预定义好的,有的是自己定义的,如programMenuFolder 就是系统定义好的,WixSetUp自己定义的。--> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramMenuFolder" > <Directory Id="ApplicationProgramsFolder" Name="WixSetUp"/> </Directory> <!--使用<Directory Id="ProgramFilesFolder">。 会安装到C:\Program Files (x86),但是要建文件的话,可能要出问题,因为要权限 WINDOWSVOLUME是在c盘下--> <Directory Id="WINDOWSVOLUME"> <Directory Id="INSTALLFOLDER" Name="SetupTestBuild" /> </Directory> <!--快捷方式使用的目录--> <Directory Id="DesktopFolder" Name="Desktop" /> </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> $(var.TestBuild.TargetDir) for Debug 模式,it is D:\QS_Working\QS_Fenix\Fenix\FENIX_R&P\Fenix.Record\bin\Debug for release 模式, it is D:\QS_Working\QS_Fenix\Fenix\FENIX_R&P\Fenix.Record\bin\Release --> <Component Id="ProductComponent" Guid="09EFA3CE-8A3A-4007-AED2-6F51CAE31A82"> <File Id="TestBuild" Name="TestBuild.exe" Source="$(var.TestBuild.TargetDir)" Checksum="yes" KeyPath="yes" Assembly=".net" AssemblyApplication="TestBuild" /> <!--<File Name="tst.mp4" Source="$(var.TestBuild.TargetDir)"/>--> </Component> <Component Id="ApplicationShortCut" Guid="9BE4B29A-F303-4913-8750-C3DD7361E313"> <!--可以使用 directory 属性来限制 快捷方式所在的目录。如果加此属性,则安装到ComponentGroup结点的目录,即installFolder 。如果不想使用directory属性,也可以在外面使用DirectoryRef,则快捷方式默认到对应的路径下--> <!--一般使用WorkingDirectory="INSTALLFOLDER"否则可能会出错,特别是启动时候--> <!--Unistall Menu shortcut--> <Shortcut Id="ApplicationUnitallMenuShortcut" Name="Unitall" Description="unitall by Lcuas" Target="[SystemFolder]msiexec.exe" Arguments="/x [ProductCode]" Directory="ApplicationProgramsFolder" /> <!--start Menu shortcut--> <Shortcut Id="ApplicationStartMenuShortcut" Name="TestBuild" Description="set up by Lucas!" Target="[INSTALLFOLDER]TestBuild.exe" WorkingDirectory="INSTALLFOLDER" Directory="ApplicationProgramsFolder" /> <!--shortcut in install folder--> <Shortcut Id="UninstallProduct" Name="Unitall" Directory="INSTALLFOLDER" Description="unitall by Lcuas" Target="[SystemFolder]msiexec.exe" Arguments="/x [ProductCode]" /> <Shortcut Id="DesktopShortCut" Directory="DesktopFolder" Name="TestBuild" Target="[INSTALLFOLDER]TestBuild.exe" WorkingDirectory="INSTALLFOLDER" /> <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Name="installed" Type="integer" Value="1" KeyPath="yes"> </RegistryValue> </Component> <!--remove files--> <Component Id="RemoveFiles" Guid='{F341A78A-44EA-40B7-BDFD-5CA09DF7EB3F}' KeyPath='yes'> <RemoveFolder Id="ApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" /> <RemoveFolder Id="INSTALLFOLDER" Directory="INSTALLFOLDER" On="uninstall" /> </Component> </ComponentGroup> </Fragment> </Wix>
参考文献:
http://blog.csdn.net/xxdddail/article/details/12652233
http://www.cnblogs.com/stoneniqiu/p/3365017.html