Search code examples
wixwindows-installer

How to set WiX default install location



i've just started using WiX, but unfortunately i've ran into problem right away.
So, i want to set default install location to, for example, `C:\Program Files (x86)\Vendor\App`, but i've only managed to set to `C:\Program Files (x86)\App`... And i couldn't find anything related...
Anyways, here's the "Product.wxs" code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define ProjectManagementNF_TargetDir=$(var.ProjectManagementNF.TargetDir)?>
    <Product Id="*" Name="AppName" Language="1033" Version="0.1.4.0" Manufacturer="Vendor" UpgradeCode="1f380795-2f0d-47fc-9950-9ab74ed5c1d9">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        
        <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
        <UIRef Id="WixUI_InstallDir" />
        
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes"/>

        <Feature Id="ProductFeature" Title="AppName" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
            <ComponentGroupRef Id="ProgramFilesFolder_files" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="App"/>
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLDIR">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <Component Id="ProductComponent">
                // some registry stuff...
            </Component>
        </ComponentGroup>
    </Fragment>
    <Fragment>
      <ComponentGroup Id="ProgramFilesFolder_files" Directory="ProgramFilesFolder">
        // some stuff..
      </ComponentGroup>
    </Fragment>
</Wix>

Any help would be appreciated,
thanks in advance!!!


Solution

  • Please try to extend the directory section with the vendor folder like this:

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="Vendor" Name="VendorName">
               <Directory Id="INSTALLDIR" Name="App">
    
                  <!-- Sample component -->
                  <Component Feature="ProductFeature">
                    <File Source="C:\Windows\notepad.exe" />
                  </Component>
    
               </Directory>
            </Directory>
        </Directory>
    </Directory>
    

    I like to avoid the <Fragment> sections for small WiX packages. See a sample of this here: https://github.com/glytzhkof/all/blob/master/WiXBitnessX64/WiXBitnessX64/Product.wxs

    You can keep all markup inside single <WiX> and <Product> element.