WiX安装选项---开始菜单项

参考文档: How To: Create a Shortcut on the Start Menu,How To: Create an Uninstall Shortcut

制作的安装程序安装后,都要在开始菜单上生成一个应用程序的菜单,通常包括调用应用程序的快速入口和卸载应用程序项。下面取一个例子来看:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="a960cf35-0779-43e8-923b-35638f2bfc42" Name="Minimal" Language="2052" Version="1.0.0.0" Manufacturer="Geffzhang" UpgradeCode="0bf7e020-5bbd-4a06-8e39-e715999edbf5">
    <Package InstallerVersion="200" Compressed="yes" Description="Minimal Windows Installer Sample" Comments="This installer database contains the logic and data required to install Minimal Windows Installer Sample." />
    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
    <Property Id="EnableEV" Value="1">
    </Property>
    
    <Condition Message="你必须有管理员权限才能安装应用程序"><![CDATA[Privileged]]></Condition>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="Minimal">
          <Component Id="Component1" Guid="{1781A625-8ACB-45E7-A8BA-219D81760B2E}">
            <CreateFolder />
            <Environment Id="TestMinVar" Action="set" Part="all" Name="MinEnvVar" Permanent="no" System="yes" Value="8" />
            <File Id="File_Payload" Source="payload.txt" KeyPath="yes" />
          </Component>
          <Directory Id="GAC" Name="GAC">
            <Component Id="RTGACTest" Guid="22887611-B13E-41EE-897C-D78830E68AEB" DiskId="1">
              <!-- Runtime, assembly in GAC -->
              <File Id="F_RT_GACTEST"  LongName="GACTest.dll" Source="..\build\GACTest.dll" KeyPath="yes" Assembly=".net" />
            </Component>
          </Directory>
          <Component Id="DTGACTest" Guid="FB935B7D-D2BD-4B83-A26C-A9376EBA0915" DiskId="1">
            <!--Design-time, private assembly-->
            <File Id="F_DT_GACTest" LongName="GACTest.dll" Source="..\build\GACTest.dll" KeyPath="yes" />
            <Registry Id="R_DT_MyControl_AssemblyFolders" Root="HKLM" Key="SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\[ProductName]" Value="[$DTGACTest]" Type="string" />
          </Component>
        </Directory>
      </Directory>
      
      <Directory Id="ProgramMenuFolder">
        <Directory Id="MinimalStartMenuFolder" Name="Minimal">
          <Component Id="StartMenuFolder" Guid="B3AEC4C4-3F8E-4865-B87A-B750533776B5" >
            <Shortcut Id="ApplicationStartMenuShortcut" 
                      Name="Minimal Test"  Target="[INSTALLLOCATION]payload.txt"
             WorkingDirectory="INSTALLLOCATION"/>
            <Shortcut Id="UninstallProduct"
                  Name="Uninstall Minimal"
                    Description="Uninstalls My Application"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"/>

            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplicationName" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>    

    <Feature Id="ProductFeature" Title="Minimal" Level="1">
      <ComponentRef Id="Component1" />
      <ComponentRef Id="DTGACTest"/>
      <ComponentRef Id="RTGACTest" />
      <ComponentRef Id="StartMenuFolder"/>
    </Feature>
    
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" />
    <UIRef Id="WixUI_InstallDir" />
    <UI />
  </Product>
</Wix>

上面例子中开始菜单项的内容是这一段:

<Directory Id="ProgramMenuFolder">
        <Directory Id="MinimalStartMenuFolder" Name="Minimal">
          <Component Id="StartMenuFolder" Guid="B3AEC4C4-3F8E-4865-B87A-B750533776B5" >
            <Shortcut Id="ApplicationStartMenuShortcut" 
                      Name="Minimal Test"  Target="[INSTALLLOCATION]payload.txt"
             WorkingDirectory="INSTALLLOCATION"/>
            <Shortcut Id="UninstallProduct"
                  Name="Uninstall Minimal"
                    Description="Uninstalls My Application"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"/>

            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplicationName" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>    
开始菜单项和要安装的应用程序要分开放在不同的Directory里面,ProgramMenuFolder是标准的Windows开始菜单,第二个Directory将是在windows开始菜单下创建的一个菜单项,我们把它命名
为Minimal,菜单的快捷方式包括三个元素:一个是Component 元素是WiX安装元素的原子单位,Component元素下的Shortcut就是快捷菜单项了,RemoveFolder 元素保证在卸载应用程序的时候
做相关的清理工作。上面的例子中有两个快捷方式,一个是Minimal Test,另一个是Uninstall Minimal,这两个就是Windows开始菜单中所看到的菜单项了。
Windows Installer System64Folder 属性在32位的机器上被解析为System32 目录,在64位的机器上被解析为 SysWow64 目录.

你可能感兴趣的:(安装)