Wix设置自定义安装文件夹(不是默认的Program Files INSTALLDIR)

时间:2017-07-09 16:10:21

标签: wix install wix3

我使用Wix项目生成安装程序MSI文件。

我的项目需要安装在特定文件夹(如C:\MyProject\Version1)中,而不是默认的Program Files文件夹中。我的文件夹所需的结构:

c:\MyProject\Version1
    |
    |--- MyProject.exe
    |--- Utils.dll
    |--- README.txt
    |
    |--- data
          |----- config.ini

这是我的Wix配置:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define eMyProjectConnectionTest_TargetDir=$(var.eMyProjectConnectionTest.TargetDir)?><?define MyProject_TargetDir=$(var.MyProject.TargetDir)?><?define MyProjectCheckLicenses_TargetDir=$(var.MyProjectCheckLicenses.TargetDir)?>
    <Product Id="1609421b-de6a-4285-b190-861ce626ab5e" Name="MyProject" Language="1033" Version="3.3.0" Manufacturer="MyProject Software LLC" UpgradeCode="f1fb7395-ff04-4eb9-942b-5c6ff889808c">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

    <!-- EmbedCab="yes" adds the CAB file to the instlal file -->
    <MediaTemplate EmbedCab="yes"/> 

    <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> -->
      <Component Id="MyProject.exe" Guid="cbea4919-c7a7-4264-925f-7c7c58a952b3">
        <File Id="MyProject.exe" Name="MyProject.exe" Source="$(var.MyProject_TargetDir)MyProject.exe" />
      </Component>

      <!-- Added files -->
      <Component Id="Utils.dll" Guid="192fee52-79e1-43cb-81c8-b8af9d4d9ecc">
        <File Id="Utils.dll" Source="Files/Utils.dll" KeyPath="yes"/>
      </Component>

      <Component Id="README.txt" Guid="c8c74065-5dd9-44d0-83ab-8838bea143e3">
        <File Id="README.txt" Source="Files/README.txt" KeyPath="yes"/>
      </Component>

    </ComponentGroup>

    <!-- Adds a start menu shortcut -->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MyProject">
          <Directory Id="data" Name="data">
            <Component Id="config.ini" Guid="8f9ee1cf-6a8a-4cc7-8d40-47c337dd9ff2">
              <File Id="config.ini" Source="Files/config.ini" KeyPath="yes"/>
            </Component>
          </Directory>
        </Directory>
      </Directory>

      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyProject"/>
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
        <Directory Id="ApplicationDesktopFolder" Name="MyProject"/>
    </Directory>

    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="33776559-768b-4dbb-a924-984146edf8fb">
        <Shortcut Id="ApplicationStartMenuShortcut"
                  Name="MyProject"
                  Description="MyProject"
                  Target="[#MyProject.exe]"
                  WorkingDirectory="INSTALLFOLDER"/>
        <RemoveFolder Id="CleanUpStartMenuShortCut" Directory="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\Microsoft\MyProject" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="09a53fb1-0447-4849-9bc4-3971f5fdbbad">
        <Shortcut Id="ApplicationDesktopShortcut"
                  Name="MyProject"
                  Description="MyProject"
                  Target="[#MyProject.exe]"
                  WorkingDirectory="INSTALLFOLDER"/>
        <RemoveFolder Id="CleanUpDesktopShortCut" Directory="ApplicationDesktopFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\Microsoft\MyProject" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <Feature Id="ProductFeature" Title="MyProjectSetup" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
      <ComponentRef Id="config.ini"/>
      <ComponentRef Id="ApplicationShortcut"/>
      <ComponentRef Id="ApplicationShortcutDesktop"/>
    </Feature>

    </Product>
</Wix>

帮助appreaciated。

1 个答案:

答案 0 :(得分:0)

您需要在ProgramFilesFolder之外添加标签class App extends React.Component { state = { randomNum: '' } componentDidMount() { this.getNewRandomNum() } getNewRandomNum = () => { let randomNum = Math.floor(Math.random() * 15) this.setState({ randomNum }) console.log(this.state.randomNum) } prevNum = () => { } render() { return ( <div> <h1>{this.state.randomNum}</h1> <button onClick={this.getNewRandomNum}>New Number</button> <button onClick={this.prevNum}>Previous Number</button> </div> ) } }