0
votes

I am trying to create a folder at a location different from the application installation location which happens to be C:\Program Files(x86). I am using the following fragment

 <Fragment>
    <DirectoryRef Id="TARGETDIR">
      <Directory Id="PhotosDir" Name="Photos" />       
    </DirectoryRef>
    <!--<SetDirectory Id="PhotosDir" Value="[TARGETDIR]Photos" Sequence="execute"></SetDirectory>-->
  </Fragment>

I tried with a SetDirectory element as shown above and also with a CustomAction as shown below. (If I use both, I get an error saying Id is duplicated. Hence I commented it.)

<CustomAction Id="SetPhotosDir" Directory="PhotosDir" Value="[TARGETDIR]Photos"></CustomAction>
    <InstallExecuteSequence>    
      <Custom Action="SetPhotosDir" Before="CreateFolders"/>
    </InstallExecuteSequence>

I have a component also defined for this directory element as below.

<Component Id="cmpPhotosDir" Guid="{8F757344-CA0A-42BC-B292-A51CE86B19E2}" KeyPath="yes" Directory="PhotosDir"><CreateFolder/></Component>

But the directory called Photos is always getting created in D drive, even though it is nested inside of TARGETDIR. I actually want to control the location where this directory gets created, probably through UI. I googled for SetDirectory element example, but couldn't find a proper working sample. All I get to see is that I have to use a custom action type 35 or 51. But it is not clear what code should go inside of these custom actions. Also, I am not sure, if these custom actions are required in addition to the SetDirectory element or not. Can anyone please help me achieve this, with some working sample?

1

1 Answers

0
votes

The problem is your directory identifier is not PUBLIC. Change its name to include no lower-case letters; use only upper-case letters, numbers, and underscores. (This came up in reverse pretty recently over here.)

I would also probably schedule the action to After="CostFinalize" , or just set the property of the same name Before="CostInitialize. Neither of those are likely to be relevant to your symptoms, however.