Changing the TARGETDIR in WiX
Asked Answered
T

5

6

I am having problems setting the TARGETDIR path. I used dark.exe to reverse engineer a working MSI file and read any posts I could find on this subject, but I seem to be unable to set the TARGETDIR to point to the path ProgramFiles\Manufacturer\Product. Below is a distilation of my WXS file which results in my application being installed to the root of my D-drive for some reason:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
             Name="FBL - Some App"
             Language="1033"
             Version="1.0.0.0"
             Manufacturer="Foo &amp; Bar Limited"
             UpgradeCode="780286c6-e064-4402-80d8-dd2c68b56c04">
        <Package InstallerVersion="200"
                 Compressed="yes"
                 InstallScope="perMachine"
                 Comments="Performs some operation that is important" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <Media Id="1" Cabinet="App.1.0.0.cab" EmbedCab="yes" />
        <CustomAction Id="setTARGETDIR"
                      Property="TARGETDIR"
                      Value="[ProgramFilesFolder][Manufacturer]\[ProductName]"
                      Execute="firstSequence"
                      Return="check" />

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Component Id="C__App.exe"
                       Guid="{074586E9-A675-2734-A4CD-1CE520922A41}">
                <File Id="F__App.exe"
                      Name="App.exe"
                      KeyPath="yes"
                      Assembly=".net"
                     AssemblyManifest="F__App.exe"
                      AssemblyApplication="F__App.exe"
                      DiskId="1"
                      Source="D:\SomePath\bin\Debug\App.exe" />
            </Component>
        </Directory>
        <Feature Id="DefaultFeature" ConfigurableDirectory="TARGETDIR" Level="1">
            <ComponentRef Id="C__App.exe" Primary="yes" />
        </Feature>
        <Icon Id="favicon.ico" SourceFile="d:\SomePath\favicon.ico" />
        <Property Id="ARPPRODUCTICON" Value="favicon.ico" />
        <UI />
        <InstallExecuteSequence>
            <Custom Action="setTARGETDIR" Before="CostFinalize" />
        </InstallExecuteSequence>
    </Product>
</Wix>

I'm sure I am missing something simple, but I cannot find any further information on what to do from here.

Tuna answered 24/10, 2012 at 20:33 Comment(0)
T
5

The following modifications were needed:

<CustomAction Id="SetTARGETDIR"
              Directory="TARGETDIR"
              Value="[ProgramFilesFolder][Manufacturer]\[ProductName]"
              Return="check" />

and

<InstallExecuteSequence>
    <Custom Action="SetTARGETDIR" After="InstallValidate" />
</InstallExecuteSequence>

Explanation: Use the Directory attribute instead of a property (it's a type 35 custom action) and schedule this action after InstallValidate in the execute sequence - that's when directories are checked for write access and truly set.

(Thanks to Narina Chandra Sekhar, from the WiX user group for the answer on this.)

Tuna answered 24/10, 2012 at 22:28 Comment(0)
B
3

This is strange...I had the same issue but your answer didn't work for me. All I needed was this:

<Product>
   <SetProperty Id='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[ProductName]\' Before='FindRelatedProducts' />
   ...
</Product>

But then again I think something else in my installer may have been setting the TARGETDIR directory from the property; I was working with some legacy stuff.

Edit: Actually, that was a bad idea. A lot of times, some of these custom actions that are built in can be called at different parts of the installation process, so its just better to add a custom action to set the property.

Here is what worked for me:

<Product>
   <CustomAction Id='SetTARGETDIR' Property='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[ProductName]\'/>
   ...
</Product>
<InstallUISequence>
   <Custom Action='SetTARGETDIR' Sequence='1'/>
   ...
</InstallUISequence>
<AdminUISequence>
   <Custom Action='SetTARGETDIR' Sequence='1'/>
   ...
</AdminUISequence>
Bemean answered 22/9, 2014 at 18:37 Comment(1)
I think there's no difference in using SetProperty if you just use in the right place, that is before CostFinalize action. Compare my answerDemoralize
B
0

Nothing worked for me so what I did is to run the msi with a command line setting the property of the installation directory. By default my program would be installed to drive C but sometimes I wanted it to be installed to D drive so here is what I did:

<Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
               <Directory Id="APPLICATIONROOTDIRECTORY" Name="XServer">                     
               </Directory>
            </Directory>
</Directory>

Here is the command line:

XServer.msi /L*v log.log APPLICATIONROOTDIRECTORY="D:\Program Files (x86)\XServer"

Bicorn answered 29/9, 2016 at 9:30 Comment(0)
D
0

This actually worked for me. The CostFinalize action is where TARGETDIR Directory is defined.

<SetProperty Id="TARGETDIR" Value="[ROOTDRIVE]MyCompany" Sequence="first" Before="CostFinalize">NOT Installed AND NOT TARGETDIR</SetProperty>
Demoralize answered 14/9, 2020 at 21:11 Comment(1)
I get an error using Wix 4 stating: WIX0400] The SetProperty element contains illegal inner text: 'NOT Installed AND NOT TARGETDIR'. What is the purpose of that text in this context? Should that be specified in the Condition attribute instead?Ctn
S
0

I tried changing the installation dir via custom action (cause I needed code to figure out the path with code - long story), and what solved it for me what the timing - I had to schedule the custom action to:

After="CostInitialize"
Sky answered 6/1, 2021 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.