How to Install Files to an Arbitrary Location Outside "Program Files"

By default WiX installs your application files into a folder under "Program Files". This is because normally you have a few lines of code like below:

      <Directory Id='TARGETDIR' Name='SourceDir'>
         <Directory Id='ProgramFilesFolder' Name='PFiles'>
            <Directory Id='MyDir' Name='TestProg' LongName='Test Program'>
               <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'>

The above WiX example deploys your files to %SystemDrive%\Program files\Test Program. However, sometimes you don't want this behavior and need to install files to an arbitrary folder. To achieve this, you can try these:

  • Don't worry about TARGETDIR
  • Create a public property (like MYAPPPATH, or INSTALLDIR) to set the new application installation location
  • Add a Directory node with Id="MYAPPPATH" and Name=".". Note: Name="." overrides the parent folder
  •       <Property Id="MYAPPPATH"><![CDATA[c:\mydir\]]></Property>             <!-- New property -->
    
          <Directory Id='TARGETDIR' Name='SourceDir'>
             <Directory Id='ProgramFilesFolder' Name='PFiles'>
                <Directory Id="MYAPPPATH" Name=".">                             <!-- Overrides the parent folder -->
                   <Directory Id='MyDir' Name='TestProg' LongName='Test Program'>
                      <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'>
    

    Now you can have what you want, enjoy WiXing!

    See also

  • Introduction to the Windows Installer XML(WiX) Toolset
  • MSI basics
  • WiX Tutorial - Steps to Create an MSI with Windows Installer XML(WiX)
  • How to Install a COM DLL with Windows Installer XML(WiX)
  • How to Add a License Agreement UI to Windows Installer XML(WiX)
  • How to Add Customization Code CustomAction to Windows Installer XML(WiX)
  • How to Reset Windows Service with Windows Installer XML(WiX)
  • How to Troubleshoot MSI Installation
  • How to Pass Parameters to the Customization Code(CustomAction)
  • How to Log Tracing Infomation to the Calling MSI from CustomAction
  • How to Invoke InstallUtil.exe to Call Your Managed Installer Class
  • How to Create a Website and Virtual Directory with Windows Installer XML(WiX)
  • How to Install Files to an Arbitrary Location Outside "Program Files"
  • How to Read Configuration Parameters from Xml File
  • How to Use Environmental Variables and WiX Preprocessor
  • Download WiXSharp



  • THIS POST IS PROVIDED "AS-IS" WITH NO WARRANTIES AND CONFERS NO RIGHTS. Build time: Sun 01/27/2008 . ©2007 Dalun Software. All rights reserved. Back to Article List