Search code examples
visual-studiowixwindows-installersetup-project

Wix : Declare or set property after ResolveSource


I try to search a file in my project. The problem is I use the var "SourceDir" and it's work fine in install with UI but no with silent install.

I found it's because SourceDir is not setted before I try to used it in silent mode.

That's why I want to set my property after the "ResolveSource" action

<Property Id='CUSTOMCONFIGFILEEXISTS'>
  <DirectorySearch Id='DirSearch' Path='[SOURCEDIR]' Depth='0'>
    <FileSearch Id='FileSearch' Name='EasyFolderApplicationDesktopToolbar.exe.config'/>
  </DirectorySearch>
</Property>

...

  <Component Id="CustomMainExecutableConfig" Guid="A952C40B-0274-4EA8-8A48-0216395455CF" Directory="INSTALLDIR" NeverOverwrite="yes">
    <Condition>CUSTOMCONFIGFILEEXISTS</Condition>
    <CopyFile Id="CustomEasyFolderApplicationDesktopToolbarCONFIG" SourceProperty="CUSTOMCONFIGFILEEXISTS" DestinationProperty="INSTALLDIR"  />
    <!--<CopyFile Id="CustomEasyFolderApplicationDesktopToolbarCONFIG" SourceProperty="CONFIGFILEEXISTS" DestinationProperty="INSTALLDIR"  />-->
  </Component>

I already try this, with no result :

<Property Id='CUSTOMCONFIGFILEEXISTS'>
  <DirectorySearch Id='DirSearch' Path='[Temp]' Depth='0'>
    <FileSearch Id='FileSearch' Name='EasyFolderApplicationDesktopToolbar.exe.config'/>
  </DirectorySearch>
</Property>

<CustomAction Id='SET_CUSTOMCONFIGFILEEXISTS'
          Property='Temp'
          Value='[SourceDir]'/>

...

<InstallExecuteSequence>
  <ResolveSource After="CostInitialize" ></ResolveSource>
  <Custom Action='SET_CUSTOMCONFIGFILEEXISTS' After='ResolveSource'></Custom>
  <Custom Action="AlreadyUpdated" After="FindRelatedProducts">SELFFOUND</Custom>
  <Custom Action="NoDowngrade" After="FindRelatedProducts">NEWERFOUND</Custom>
  <RemoveExistingProducts After="InstallExecute" />
</InstallExecuteSequence>

I already see this How do I use the SourceDir MSI property in WiX? But I don't know how to do...

Can you help me ?


Solution

  • That search is ultimately an AppSearch, and in a WiX-built MSI that's the first thing that runs, so your 'CUSTOMCONFIGFILEEXISTS' property has already been processed by the search, so it's false by the time that component results in the component not being installed and the copyfile not being done. So the reason for the failure is not ResolveSource - it's because 'CUSTOMCONFIGFILEEXISTS' is being set false and you are conditioning the component and the copyfile on that false condition.

    IMO you are over-thinking this. Don't bother with a search. Just pick a component relevant to the file you want to copy (don't invent a transitional component for it with a condition). Add the CopyFile to that component with [SourceDir] as the source. If the file is there it will be copied, if not then it won't be.

    Don't add an unconditional ResolveSource action because it will happen every time the an installer action takes place (repair, removing features, patches, uninstall) and that is generally unnecessary. In any case I am certain you do not need a ResolveSource. There is an implicit ResolveSource at first install or it wouldn't even know where the MSI was! Just do the copyfile as I suggested.