简体   繁体   中英

Changing the TARGETDIR in WiX

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.

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.)

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>

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"

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>

我尝试通过自定义操作更改安装目录(因为我需要代码来找出带有代码的路径 - 长话短说),以及是什么为我解决了这个问题 - 我必须将自定义操作安排为:

After="CostInitialize"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM