简体   繁体   中英

Add file to Wix installer if it exists

I am trying to add a file to the installer like this in my main wxs file.

    <ComponentGroup Id="Files" Directory="Bin">
        <?if $(var.FILE_EXISTS) = "true"?>
            <Component>
                <Condition>$(var.FILE_EXISTS) = "true"</Condition>
                <File Source="$(var.SourceDir)/file.txt"/>
            </Component>
    </ComponentGroup>

I'm passing FILE_EXISTS through candle.exe with the -d option

But its not taking effect. Its not getting added. It works when I don't have the conditions (just the File element). Any ideas?

As far as I understand, the condition you are talking about is a build-time condition. Basically, you would like to control whether the file in question gets into the MSI package.

If that's correct, then one mistake is the <Condition> element under <Component> . That's install-time condition, and only influences then the file is installed.

The other one is a pure syntax issue. The <?if?> directive must have the closing element.

Taking the above into account, your snippet might look like this:

<ComponentGroup Id="Files" Directory="Bin">
  <?if $(var.FILE_EXISTS) = "true"?>
  <Component>
    <File Source="$(var.SourceDir)/file.txt"/>
  </Component>
  <?endif?>
</ComponentGroup>

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